C Program To Calculate Area Of Equilatral Triangle
Maybe your like
In this tutorial, you will learn how to write a C program to calculate area of an equilateral triangle. A triangle is called equilateral triangle if all three of its sides are equal.
Formula to calculate area of an equilateral triangle:
Area = (sqrt(3)/4 )* (side * side)C Program to calculate Area of an Equilateral triangle
The explanation of the program is available at the end of this program.
#include <stdio.h>#include <math.h>int main() { float side, area; // Prompt user for the side length printf("Enter the side length of the equilateral triangle: "); scanf("%f", &side); // Calculate the area of equilateral triangle area = (sqrt(3) / 4) * (side * side); // print the area value after calculation printf("Area of the equilateral triangle: %.2f\n", area); return 0;}Output:
Output 1:
Enter the side length of the equilateral triangle: 5Area of the equilateral triangle: 10.83Output 2:
Enter the side length of the equilateral triangle: 25Area of the equilateral triangle: 270.51Explanation:
- Include Standard Libraries:
- #include <stdio.h> for standard input and output functions such as printf and scanf.
- #include <math.h> The sqrt function which we have used in the program is present in this library.
- Declare Variables:
- float side, area; The side variable is to hold the value of side of the equilateral triangle and area variable is to hold the area value after calculation.
- User Input:
- printf("Enter the side length of the equilateral triangle: "); prompts the user to enter the length of side of triangle.
- scanf("%f", &side); reads the value entered by user and store it into the side variable.
- Calculate Area:
- area = (sqrt(3) / 4) * (side * side); This formula is used for calculating the area.
- Print Result:
- printf("Area of the equilateral triangle: %.2f\n", area); prints the area of equilateral triangle with two decimal places.
- Return Statement:
- return 0; indicates that the program executed successfully.
Top Related Articles:
- C Program to print cube of a number upto an integer
- C Program to concatenate two strings without using strcat
- C Program to read and print employee details using structure
- C Program to Print Right Triangle Star Pattern
- C Program to find greatest of three numbers
Tag » Area Of Equilateral Triangle C Program
-
C Program To Find Area Of An Equilateral Triangle - Codeforwin
-
C Program To Find Area Of An Equilateral Triangle - Tutorial Gateway
-
C Program To Calculate Area Of An Equilateral Triangle
-
Program To Find The Area Of An Equilateral Triangle - Javatpoint
-
C Program To Find Area Of An Equilateral Triangle - CodingBroz
-
C Program To Find Area Of Equilateral Triangle - Codingeek
-
C Program To Calculate The Area Of An Equilateral Triangle
-
C Program Area Of Equilateral Triangle - Java Tutoring
-
Find Area Of An Equilateral Triangle: C Program
-
C Program To Find Area Of An Equilateral Triangle - Tuts Make
-
C Program To Check Whether The Triangle Is Equilateral, Isosceles Or ...
-
C++ Exercises: Calculate Area Of An Equilateral Triangle - W3resource
-
C Program To Find Area Of Equilateral Triangle - Oodlescoop
-
C Program To Find Area Of Equilateral Triangle