Answer to Question #48743 in C++ for ama

Question #48743
Given the lengths a,b,c of the sides of triangle, write a function based program to compute the area of the triangle., The formula for computing the area is given by: Area = √ s(s-a)(s-b)(s-c) where s is the semiparameter of the triangle s=(a+b+c)/2
Expert's answer
#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;
float Area( float a, float b, float c )
{
float s = ( a + b + c) / 2;
float area = sqrt( s*(s-a)*(s-b)*(s-c));
return area;
}
int main()
{
float a, b,c; // lengths of sides
cout << "Enter a: ";
cin >> a;
cout << "Enter b: ";
cin >> b;
cout << "Enter c: ";
cin >> c;
printf("The area of triangle is: %3.2f\n", Area(a,b,c)); //call of the function and print result
system("PAUSE");
return EXIT_SUCCESS;
}

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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS
paypal