To calculate the area of a Triangle we need to have the lengths of all three sides, using "Heron's Formula" that has been known for nearly 2000 years. The following simple program inputs three sides of a triangle from the user and finds out triangle area by Heron's Formula:
Where:
s = (a + b + c)/2
Program Source Code
#include
#include
main()
{
float s, a, b, c, area;
std :: cout
std :: cin>>a;
std :: cout
std :: cin>>b;
std :: cout
std :: cin>>c;
s = (a+b+c) / 2.0;
area = sqrt (s*(s-a)*(s-b)*(s-c));
std:: cout std :: cout return 0;
}
Output of Program
Enter first side of triangle: 30Enter second side of triangle: 40
Enter third side of triangle: 60
The sides of triangle = 30, 40, 60
Area of triangle = 533.268