Advertisement
Sanlover

Untitled

Sep 26th, 2021
1,069
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.58 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     SetConsoleOutputCP(1251);
  8.     double x1, x2, x3;
  9.     double y1, y2, y3;
  10.     double ab, bc, ac;
  11.  
  12.     // Input
  13.     cout << "Enter the coordinates of the first point: ";
  14.     cin >> x1 >> y1;
  15.  
  16.     cout << "Enter the coordinates of the second point: ";
  17.     cin >> x2 >> y2;
  18.  
  19.     cout << "Enter the coordinates of the third point: ";
  20.     cin >> x3 >> y3;
  21.  
  22.     // Side calculations
  23.     ab = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
  24.     bc = sqrt((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2));
  25.     ac = sqrt((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1));
  26.  
  27.     // If any side is equal to other, than we need to exit the program cos of
  28.     if (ab == bc || bc == ac || ab == ac)
  29.     {
  30.         cout << "One of the sides is equal to other";
  31.         return 0;
  32.     }
  33.  
  34.     if (ab >= bc + ac || bc >= ac + ab || ac >= bc + ab)
  35.     {
  36.         cout << "Треугольник не существует." << endl;
  37.         return 0;
  38.     }
  39.  
  40.     double eps = 0.0001;
  41.     // Проверка на то, является ли введённый треугольник остроугольным
  42.     if (ab * ab - abs(ac * ac + bc * bc) <= eps || bc * bc - abs(ac * ac + ab * ab) <= eps ||
  43.         ac * ac - abs(ab * ab + bc * bc) <= eps)
  44.     {
  45.         cout << "Треугольник прямоугольный." << endl;
  46.     }
  47.     else if (ab * ab < ac * ac + bc * bc && bc * bc >= ac * ac + ab * ab && ac * ac >= ab * ab + bc * bc ||
  48.              bc * bc < ac * ac + ab * ab && ab * ab < ac * ac + bc * bc && ac * ac >= ab * ab + bc * bc ||
  49.              ac * ac < ab * ab + bc * bc && ab * ab < ac * ac + bc * bc && bc * bc >= ac * ac + ab * ab)
  50.     {
  51.         cout << "Треугольник тупоугольный." << endl;
  52.         double square, halfP;
  53.         double h1, h2, h3;
  54.  
  55.         // полупериметр и площадь
  56.         halfP = (ab + bc + ac) / 2.0;
  57.         square = sqrt(halfP * (halfP - ab) * (halfP - ac) * (halfP - bc));
  58.  
  59.         // Высоты
  60.         h1 = 2 * square / ab;
  61.         h2 = 2 * square / bc;
  62.         h3 = 2 * square / ac;
  63.  
  64.         cout << endl << "Высоты треугольника в порядке возрастания: " << endl;
  65.         if (h1 <= h2)
  66.         {
  67.             if (h1 <= h3)
  68.             {
  69.                 cout << h1 << " ";
  70.                 if (h2 <= h3)
  71.                 {
  72.                     cout << h2 << " ";
  73.                     cout << h3 << " ";
  74.                 }
  75.                 else
  76.                 {
  77.                     cout << h3 << " ";
  78.                     cout << h2 << " ";
  79.                 }
  80.             }
  81.             else
  82.             {
  83.                 cout << h3 << " ";
  84.                 if (h2 <= h1)
  85.                 {
  86.                     cout << h2 << " ";
  87.                     cout << h1 << " ";
  88.                 }
  89.                 else
  90.                 {
  91.                     cout << h1 << " ";
  92.                     cout << h2 << " ";
  93.                 }
  94.             }
  95.         }
  96.         else
  97.         {
  98.             if (h2 <= h3)
  99.             {
  100.                 cout << h2 << " ";
  101.                 if (h1 <= h3)
  102.                 {
  103.                     cout << h1 << " ";
  104.                     cout << h3 << " ";
  105.                 }
  106.                 else
  107.                 {
  108.                     cout << h3 << " ";
  109.                     cout << h1 << " ";
  110.                 }
  111.             }
  112.         }
  113.     }
  114.     else
  115.     {
  116.         cout << "Треугольник  остроугольный." << endl;
  117.     }
  118.  
  119.     return 0;
  120. }
  121.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement