Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <iostream>
- using namespace std;
- int main()
- {
- SetConsoleOutputCP(1251);
- double x1, x2, x3;
- double y1, y2, y3;
- double ab, bc, ac;
- // Input
- cout << "Enter the coordinates of the first point: ";
- cin >> x1 >> y1;
- cout << "Enter the coordinates of the second point: ";
- cin >> x2 >> y2;
- cout << "Enter the coordinates of the third point: ";
- cin >> x3 >> y3;
- // Side calculations
- ab = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
- bc = sqrt((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2));
- ac = sqrt((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1));
- // If any side is equal to other, than we need to exit the program cos of
- if (ab == bc || bc == ac || ab == ac)
- {
- cout << "One of the sides is equal to other";
- return 0;
- }
- if (ab >= bc + ac || bc >= ac + ab || ac >= bc + ab)
- {
- cout << "Треугольник не существует." << endl;
- return 0;
- }
- double eps = 0.0001;
- // Проверка на то, является ли введённый треугольник остроугольным
- if (ab * ab - abs(ac * ac + bc * bc) <= eps || bc * bc - abs(ac * ac + ab * ab) <= eps ||
- ac * ac - abs(ab * ab + bc * bc) <= eps)
- {
- cout << "Треугольник прямоугольный." << endl;
- }
- else if (ab * ab < ac * ac + bc * bc && bc * bc >= ac * ac + ab * ab && ac * ac >= ab * ab + bc * bc ||
- bc * bc < ac * ac + ab * ab && ab * ab < ac * ac + bc * bc && ac * ac >= ab * ab + bc * bc ||
- ac * ac < ab * ab + bc * bc && ab * ab < ac * ac + bc * bc && bc * bc >= ac * ac + ab * ab)
- {
- cout << "Треугольник тупоугольный." << endl;
- double square, halfP;
- double h1, h2, h3;
- // полупериметр и площадь
- halfP = (ab + bc + ac) / 2.0;
- square = sqrt(halfP * (halfP - ab) * (halfP - ac) * (halfP - bc));
- // Высоты
- h1 = 2 * square / ab;
- h2 = 2 * square / bc;
- h3 = 2 * square / ac;
- cout << endl << "Высоты треугольника в порядке возрастания: " << endl;
- if (h1 <= h2)
- {
- if (h1 <= h3)
- {
- cout << h1 << " ";
- if (h2 <= h3)
- {
- cout << h2 << " ";
- cout << h3 << " ";
- }
- else
- {
- cout << h3 << " ";
- cout << h2 << " ";
- }
- }
- else
- {
- cout << h3 << " ";
- if (h2 <= h1)
- {
- cout << h2 << " ";
- cout << h1 << " ";
- }
- else
- {
- cout << h1 << " ";
- cout << h2 << " ";
- }
- }
- }
- else
- {
- if (h2 <= h3)
- {
- cout << h2 << " ";
- if (h1 <= h3)
- {
- cout << h1 << " ";
- cout << h3 << " ";
- }
- else
- {
- cout << h3 << " ";
- cout << h1 << " ";
- }
- }
- }
- }
- else
- {
- cout << "Треугольник остроугольный." << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement