Courses

Mar 302021

# Program to find the area of triangle

0 Suresh Chand March 30, 2021

In this example, We will learn to calculate the area of a triangle. This program will calculate the area of any type of triangle.

We will use following formula to calculate area of the triangle

## Area of triangle

For detail explanation of area of a triangle, You can check this website.

Lets look an example to make clear concepts

## CODE:

``````#include <iostream>
#include <cmath>

using namespace std;

int main()
{
int a, b, c;

cout << "Enter the three sides of the triangle\n";

//taking input from user
cin >> a >> b >> c;

//calculating s
float s = (float)(a + b + c) / 2;

//calculating area
float area = sqrt(s * (s - a) * (s - b) * (s - c));

//printing the area
cout << "Area of triangle = " << area << " sqt. unit" << endl;

return 0;
}``````

The output of above program is

``````Enter the three sides of the triangle
5
4
3
Area of triangle = 6 sqt. unit``````
Subscribe
Notify of
Inline Feedbacks