The area of a triangle whose sides a, b, and c can be computed by the formula:
𝑨𝒓𝒆𝒂 𝒐𝒇 𝑻𝒓𝒊𝒂𝒏𝒈𝒍𝒆 = √𝑠((𝑠 − 𝑎)(𝑠 − 𝑏)(𝑠 − 𝑐))
where S = (a+b+c)/2. On the other hand, the hypotenuse of a right triangle can be computed using the
formula:
3. 𝐻𝑦𝑝𝑜𝑡𝑒𝑛𝑢𝑠𝑒 = √𝑎
2 + 𝑏
2 .
Write a program that can compute for the Area of a Triangle and the Hypotenuse of a right triangle. Your
program must allow the user to choose what computation to take first. Only one computation at a time. Use
a function for each computation. Allow the user to repeat the entire process as often as he/she wants
#include <bits/stdc++.h>
using namespace std;
int main()
{
double s, p, a, b, c, ta, tb, tc, ts;
cin >> a >> b >> c;
p = (a+b+c)/2;
s = sqrt(p*(p-a)*(p-b)*(p-c));
cout << s << '\n';
cin >> ta >> tb;
tc = sqrt(ta*ta+tb*tb);
cout << tc << ' ' << (ta*tb)/3;
}
Comments
Leave a comment