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