In this tutorial you will learn about the C Program to Find Find Area of an Equilateral Triangle and its application with practical example.
C Program to Find Area of an Equilateral Triangle
In this tutorial, we will learn to create a C program that will Find the Area of an Equilateral Triangle in C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- While loop in C programming.
- Conditional Statements in C programming.
What is an Equilateral triangle?
In an equilateral triangle, all the sides are of the same length. All the angles of the equilateral triangle are 60 degrees.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the required variables for the program. 2. Taking the input size of the side of the triangle. 3. Calculating the area of the equilateral triangle using the code. 4. Printing the area of an equilateral triangle. 5. End the program. |
Program description that will print the area of an equilateral Triangle:-
In today’s tutorial, we will create a program, that will calculate the area of an equilateral triangle using C programming. First, take the input size of the side of the equilateral triangle by the user. Then we will calculate the area of that triangle using the mathematical expression. At last, we will print the area of an equilateral triangle.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
//including the required header files. #include<stdio.h> #include<math.h> int main() { //Declaring the required variable for the program. float length; float ar, pr, sm, alt; //length = it will hold the length of the side of the triangle. //ar = it will hold the value for the area of triangle //pr = it will hold the value for the Perimeter of the triangle. //sm = it will hold the value for the semi-Perimeter. //alt = it will hold the value for the Altitude. //taking the input from the user for the program printf("\n Please Enter Length of any side\n"); //scanning the length of the side of the triangle. scanf("%f",&length); //Performing the calculations ar = (sqrt(3)/4)*(length*length); pr = 3*length; sm = pr/2; alt = (sqrt(3)/2)*length; //Printing the Area of Equilateral Triangle printf("\n Area of Equilateral Triangle = %.2f\n",ar); //Printing the Perimeter of Equilateral Triangle printf("\n Perimeter of Equilateral Triangle = %.2f\n", pr); //Printing the semi Perimeter of Equilateral Triangle printf("\n Semi Perimeter of Equilateral Triangle = %.2f\n", sm); //Printing the altitude of Equilateral Triangle printf("\n Altitude of Equilateral Triangle = %.2f\n", alt); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- length = it will hold the integer value for the input size of the side for the triangle.
- ar = it will hold the integer value for the area of a triangle.
- pr = it will hold the integer value for the perimeter of a triangle.
- sm = it will hold the integer value for the semi perimeter of a triangle.
Input the size of the side of the triangle.
Code to calculate the area of the triangle.
Printing output the area of an equilateral triangle.