Question #279460

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

Expert's answer

#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS