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
For detail explanation of area of a triangle, You can check this website.
Lets look an example to make clear concepts
using namespace std;
int a, b, c;
cout << "Enter the three sides of the triangle\n";
//taking input from user
cin >> a >> b >> c;
float s = (float)(a + b + c) / 2;
float area = sqrt(s * (s - a) * (s - b) * (s - c));
//printing the area
cout << "Area of triangle = " << area << " sqt. unit" << endl;
The output of above program is
Enter the three sides of the triangle
Area of triangle = 6 sqt. unit
Get the latest tutorials, examples and projects updates.
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