Calculate Area of an Equilateral Triangle in C

It calculates the area of any equilateral triangle with the given length of the side.

Source code :

#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;

Output :

Enter the length of a single side on the triangle: 5
Area of the equilateral triangle :  10.825317 sq.units

Notes :

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.

Algorithm :

  1. Get the side length from the user.
  2. calculate the area using the formula.
  3. print the area.

Output :


Comments :