C++ program to calculate the area of an equilateral triangle
ADVERTISEMENTS
C++ program to calculate the area of an equilateral triangle. There are you will learn how to find the area of an equilateral triangle in the C++ language.
Formula:
a = (sqrt(3) / 4) * (s * s)
Where:
a = area
s = side
Let us understand this example through the C++ program:
// C++ program to calculate the area of an equilateral triangle
#include <iostream>
#include <cmath>
// Used for sqrt() function
using namespace std;
int main() {
float s, a;
// s = side
// a = area
cout << "Enter the side of an equilateral triangle::\n";
cin >> s;
// Calculate area of equilateral triangle
a = (sqrt(3) / 4) * (s * s);
// Output
cout << "\nArea of the equilateral triangle = " << a << " sq. units";
return 0;
}
Output:
Enter the side of an equilateral triangle::
7
Area of the equilateral triangle = 21.2176 sq. units