Home > Backend Development > C++ > body text

Program to calculate the area and perimeter of an equilateral triangle

WBOY
Release: 2023-09-06 15:21:16
forward
1295 people have browsed it

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

Code Logic

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,

Example

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;
}
Copy after login

Output

perimeter is 15
area is 10.825317
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template