fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. // Variables for the coordinates of the vertices of the quadrilateral
  9. double x1, y1, x2, y2, x3, y3, x4, y4;
  10.  
  11. // Input of the coordinates of the vertices
  12. cout << "Enter the coordinates of the four vertices of the quadrilateral:\n";
  13. cout << "Coordinates of vertex A (x1, y1): ";
  14. cin >> x1 >> y1;
  15. cout << "Coordinates of vertex B (x2, y2): ";
  16. cin >> x2 >> y2;
  17. cout << "Coordinates of vertex C (x3, y3): ";
  18. cin >> x3 >> y3;
  19. cout << "Coordinates of vertex D (x4, y4): ";
  20. cin >> x4 >> y4;
  21.  
  22. // Comparison of the diagonal
  23. double diagonal_AC = sqrt(pow(x3 - x1, 2) + pow(y3 - y1, 2)); // Diagonal AC
  24. double diagonal_BD = sqrt(pow(x4 - x2, 2) + pow(y4 - y2, 2)); // Diagonal BD
  25.  
  26. // Comparison of the diagonals
  27. cout << fixed << setprecision(2);
  28. if (diagonal_AC > diagonal_BD) {
  29. cout << "The longer diagonal is AC = " << diagonal_AC << endl;
  30. } else if (diagonal_BD > diagonal_AC) {
  31. cout << "The longer diagonal is BD = " << diagonal_BD << endl;
  32. } else {
  33. cout << "Both diagonals are equal: AC = BD = " << diagonal_AC << endl;
  34. }
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Enter the coordinates of the four vertices of the quadrilateral:
Coordinates of vertex A (x1, y1): Coordinates of vertex B (x2, y2): Coordinates of vertex C (x3, y3): Coordinates of vertex D (x4, y4): Both diagonals are equal: AC = BD = 0.00