C++ Program to Find Area of Triangle
Here you will know about Area of Triangle and get and the example code of C++ Program to Find Area of Triangle.
Area of triangle formula
A = 1/2 * b * h
where A is the area of the triangle, b is the base of the triangle, and h is the height of the triangle.
Example of C++ Program to Find Area of Triangle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include <iostream> #include <cmath> using namespace std; int main() { float a, b, c; cout << "Enter three sides of triangle: "; cin >> a >> b >> c; // calculate semi-perimeter float s = (a + b + c) / 2; // calculate area float area = sqrt(s * (s - a) * (s - b) * (s - c)); cout << "Area of triangle is : " << area; return 0; } |
Output
Enter three sides of triangle: 4
5
7
Area of triangle is : 9.79796
Check out our other C++ programming Examples