C program to find area of an equilateral triangle

Write a C program to input side of an equilateral triangle from user and find area of the given equilateral triangle. How to find area of an equilateral triangle if sides of the triangle are given in C programming. C program to calculate area of an equilateral triangle if its side is given.

Example:
Input side of the equilateral triangle: 10
Output area: 43.3 sq. units.

Required knowledge

Fundamentals of C, Data types, Talking user input in C

Area of equilateral triangle

Area of equilateral triangle can be given by below formula:
Formula of area of equilateral triangle

Program

/**
 * C program to find area of an equilateral triangle
 */

#include <stdio.h>
#include <math.h> //Used for sqrt() function

int main()
{
    float side, area;

    // Reads side of equilateral trianlge
    printf("Enter side of an equilateral triangle: ");
    scanf("%f", &side);

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

    printf("Area of equilateral triangle = %.2f sq. units.", area);

    return 0;
} 


Output
X
_
Enter side of an equilateral triangle: 75
Area of equilateral triangle = 2435.69 sq. units.

Note: sqrt() function is used to calculate the square root of any number. Read more about how to find square root of any number.

Happy coding ;)


Any doubt or suggestion write here. I will try my best to help. Before posting your code you must escape it to view. To format your source code and use format highlighting, post your source code inside
< code >< pre > -- Your source code -- < /pre >< /code > (Remove spaces from pre and code tags).

1 comment: