#include <iostream> #include <cmath> using namespace std; int main() { int choice; cout << "Choose a formula to calculate the area of a triangle:" << endl; cout << "1. S=a*h/2" << endl; cout << "2. S=1/2*a*b*sin C" << endl; cout << "3. S=sqrt(p(p-a)*(p-b)*(p-c))" << endl; cin >> choice; if (choice == 1) { float a, h; cout << "Enter the base and height of the triangle: "; cin >> a >> h; float area = a * h / 2; cout << "The area of the triangle is: " << area << endl; } else if (choice == 2) { float a, b, C; cout << "Enter the two sides of the triangle and the angle between them: "; cin >> a >> b >> C; float area = 0.5 * a * b * sin(C); cout << "The area of the triangle is: " << area << endl; } else if (choice == 3) { float a, b, c; cout << "Enter the three sides of the triangle: "; cin >> a >> b >> c; float p = (a + b + c) / 2; float area = sqrt(p * (p - a) * (p - b) * (p - c)); cout << "The area of the triangle is: " << area << endl; } else { cout << "Invalid choice. Please choose a valid option." << endl; } return 0; }
Это программа на языке C++, которая запрашивает у пользователя выбор формулы для вычисления площади треугольника и вводит необходимые параметры для расчета. Результат выводится на экран.
#include <cmath>
using namespace std;
int main() {
int choice;
cout << "Choose a formula to calculate the area of a triangle:" << endl;
cout << "1. S=a*h/2" << endl;
cout << "2. S=1/2*a*b*sin C" << endl;
cout << "3. S=sqrt(p(p-a)*(p-b)*(p-c))" << endl;
cin >> choice;
if (choice == 1) {
float a, h;
cout << "Enter the base and height of the triangle: ";
cin >> a >> h;
float area = a * h / 2;
cout << "The area of the triangle is: " << area << endl;
} else if (choice == 2) {
float a, b, C;
cout << "Enter the two sides of the triangle and the angle between them: ";
cin >> a >> b >> C;
float area = 0.5 * a * b * sin(C);
cout << "The area of the triangle is: " << area << endl;
} else if (choice == 3) {
float a, b, c;
cout << "Enter the three sides of the triangle: ";
cin >> a >> b >> c;
float p = (a + b + c) / 2;
float area = sqrt(p * (p - a) * (p - b) * (p - c));
cout << "The area of the triangle is: " << area << endl;
} else {
cout << "Invalid choice. Please choose a valid option." << endl;
}
return 0;
}
Это программа на языке C++, которая запрашивает у пользователя выбор формулы для вычисления площади треугольника и вводит необходимые параметры для расчета. Результат выводится на экран.