C Program to calculate Area of Equilatral triangle

June 5, 2021

An equilateral triangle has equal sides(all three sides are equal). In this tutorial, we have shared a C program, which takes triangle side as input and calculates & displays the area as output.

Program to calculate Area

In order to calculate the area of equilateral triangle, we must know the side of the triangle. This program would prompt user to enter the side of the equilateral triangle and based on the value, it would calculate the area.

Formula used in the program:
Area = sqrt(3)/4 * side * side
Here sqrt refers the “square root”, this is a predefined function of “math.h” header file. In order to use this function, we have included the “math.h” header file in the program.

#include<stdio.h>
#include<math.h>
int main()
{
   int triangle_side;
   float triangle_area, temp_variable;

   //Ask user to input the length of the side
   printf("\nEnter the Side of the triangle:");
   scanf("%d",&triangle_side);

   //Caluclate and display area of Equilateral Triangle
   temp_variable = sqrt(3) / 4 ;
   triangle_area = temp_variable * triangle_side * triangle_side ;
   printf("\nArea of Equilateral Triangle is: %f",triangle_area);
   return(0);
}

Output:

Enter the Side of the triangle: 2
Area of Equilateral Triangle is: 1.732051

admin