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

C plus program to find area of trangle
Formula: Area of a 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
guest
0 Comments
Inline Feedbacks
View all comments

Join Our Newsletter Now

Get the latest tutorials, examples and projects updates.

!

Ads

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Disable Ad Block

Want Same System