Составить программу вычисления площади треугольника по любой из трех формул. S=a*h/2; S=1/2*a*b*sin C; S=sqr(p(p-a)*(p-b)*(p-c));

29 Мар 2020 в 19:41
149 +1
0
Ответы
1
#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++, которая запрашивает у пользователя выбор формулы для вычисления площади треугольника и вводит необходимые параметры для расчета. Результат выводится на экран.

18 Апр 2024 в 15:13
Не можешь разобраться в этой теме?
Обратись за помощью к экспертам
Гарантированные бесплатные доработки в течение 1 года
Быстрое выполнение от 2 часов
Проверка работы на плагиат
Поможем написать учебную работу
Прямой эфир