Home > Article > Backend Development > Program to calculate the area and perimeter of an equilateral triangle
A triangle is a closed figure with three sides. All sides of an equilateral triangle are equal. The area and perimeter of an equilateral triangle can be calculated using the following formula:
Area of an equilateral triangle = (√3)/4*a2
of an equilateral triangle Perimeter = 3 * a
To calculate the area of an equilateral triangle, the program uses the square root and power functions. The math library has these two functions that can be used to perform calculations in programs.
The following code shows the program to calculate the area and perimeter of an equilateral triangle,
Live demonstration
#include <stdio.h> #include <math.h> int main(){ int side = 5, perimeter; float area; perimeter = (3 * side); area = (sqrt(3)/4)*(side*side); printf("perimeter is %d</p><p>", perimeter); printf("area is %f", area); return 0; }
perimeter is 15 area is 10.825317
The above is the detailed content of Program to calculate the area and perimeter of an equilateral triangle. For more information, please follow other related articles on the PHP Chinese website!