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; }
Comments
Leave a comment