It calculates the area of any equilateral triangle with the given length of the side.
#include <stdio.h> #include <math.h> // for sqrt() function int main() { float length, area; printf("Enter the length of a single side on the triangle:\n "); scanf("%f", &length); area = (sqrt(3) / 4) * (length* length);// calculates the area printf("Area of the equilateral triangle : %f sq.units", area); return 0; }
Enter the length of a single side on the triangle: 5 Area of the equilateral triangle : 10.825317 sq.units
The formula to calculate the area of the equilateral triangle ,
Area = (√3/4) (side)²
, whereas side is one of the sides of the equilateral triangle.
Including <math.h> helps to calculate square root using sqrt() function.
Comments :