# C++ Program To Find Area of Triangle Using Heron’s Formula

Heron’s formula is used to calculate area of triangle. To apply this formula, lengths of all three sides of triangle should be known.

Let’s suppose that a,b and c are three sides of a triangle, then Heron’s formula to find area of triangle would be:

In above formula, “A” is area of triangle while “s” is the half of triangle perimeter. To calculate “s”, we use

The formula is named after Heron of Alexandria, who was a Greek Engineer and Mathematician in 10 – 70 AD.

## Code Explanation:

In this program, we included a header file named math.h. This file defines various mathematical functions like abs, pow, cos etc. We included this file in our program to use sqrt() function.

The program completes its processing in just two steps. First it takes lengths of three sides as input from user and calculates the half of triangle perimeter. The formula for calculation of half perimeter was:

s=(a+b+c)/2

In second step, it calculates the area of triangle. Here we used sqrt() function  which calculates the square root. This function will not work if you don’t include math.h header file in your program.The formula for calculation of area was:

area=sqrt(s*(s-a)*(s-b)*(s-c))

After that, it prints area of triangle on screen.

Recommended reading: Program To Find Area and Perimeter of Rectangle in C++

I want to mention here that if length of one side is bigger than length of other two sides combined then this shape is not considered triangle. In this case, the program will output area as zero.