C++ program that reads three sides of triangle find area of triangle
In this post we will discuss the C++ program of how to read three sides of a triangle and find its area.
In order to find the area of a triangle with 3 sides, we use the Heron’s formula which implies if a, b, and c are the three sides of a triangle, then its area is,
Area = √[s(s-a)(s-b)(s-c)]
where, s is the semi-perimeter of the triangle, i.e. s = (a + b + c)/2
C++ Program that reads three sides of triangle find area of triangle
// Program Calculate Area of triangle when three sides are given
using namespace std;
#include<iostream>
#include<math.h>
int main()
{
float a,b,c,s,area;
cout<<"Enter the three sides of triangle: "<<endl;
cin>>a>>b>>c;
s = (a+b+c)/2;
area = sqrt(s*(s-a)*(s-b)*(s-c));
cout<<"triangle sides are:"<<endl;
cout<<"a= "<<a<<endl<<"b= "<<b<<endl<<"c= "<<c<<endl;
cout<<"area of triangle is: "<<area<<endl;
return 0;
}
Output :-


