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
1
Expert's answer
2014-11-12T00:39:54-0500
#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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS