C Program to Find Area of an Equilateral Triangle

In this post, we will learn how to find the area of an equilateral triangle using the C Programming language.

A triangle having all the sides equal and each angle equal to 60 degrees is called an equilateral triangle

The formula to calculate the area of an equilateral triangle is:  Area of Equilateral Triangle = (√3/4) * (side)2.

We will use this formula in our program to find the area of an equilateral triangle.

So, without further ado, let’s begin this tutorial.

C Program to Find Area of an Equilateral Triangle

// C Program to Find Area of an Equilateral Triangle
#include <stdio.h>
#include <math.h>
int main(){
    float side, area;
    
    // Asking for input
    printf("Enter the side of an equilateral triangle: ");
    scanf("%f", &side);
    
    // Calculating area of equilateral triangle
    area = (sqrt(3) / 4) * (side * side);
    
    // Display result
    printf("Area of the triangle = %.2f", area);
    return 0;
}

Output

Enter the side of an equilateral triangle: 9
Area of the triangle = 35.07

How Does This Program Work?

    float side, area;

In this program, we have declared two floating data type variables named side and area.

    // Asking for input
    printf("Enter the side of an equilateral triangle: ");
    scanf("%f", &side);

Then, the user is asked to enter the side of the equilateral triangle. This gets stored in the side named variable.

    // Calculating area of equilateral triangle
    area = (sqrt(3) / 4) * (side * side);

We calculate the area of the equilateral triangle using the formula: area = (√3/4) * (side)2. Here, the sqrt() function is used to find the square root of a number. It is defined in the math.h header file.

    // Display result
    printf("Area of the triangle = %.2f", area);

Finally, the area of the equilateral triangle is displayed on the screen using the printf() function. We have used %.2f format specifier to limit the area to 2 decimal places.

Conclusion

I hope after going through this post, you understand how to find the area of an equilateral triangle using the C Programming language.

If you have any doubt regarding the program, then contact us in  the comment section. We will be delighted to assist you.

Also Read:

Leave a Comment

Your email address will not be published. Required fields are marked *