Calculate Area of Triangle with given three sides in C++ : Heron’s Formula for the area of a triangle(Hero’s Formula) A method for calculating the area of a triangle when you know the lengths of all three sides. Let a,b,c be the lengths of the sides of a triangle.
Heron’s formula states that the area of a triangle whose sides have lengths a, b, and c is
C++ Program to Calculate Area of Triangle
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
int main()
{
float a,b,c,S,Area;
cout<<"Enter the value of first side:";
cin>>a;
cout<<"Enter the value of second side:";
cin>>b;
cout<<"Enter the value of third side:";
cin>>c;
S=(a+b+c)/2;
Area=sqrt(S*(S-a)*(S-b)*(S-c));
cout<<"This is the Required area:"<<Area;
getch();
}
Output of Program
Enter height and base : 6 8
Area of triangle is : 24
Enter Length of Triangle’s three sides : 10
20
20
Area of Triangle is : 96