ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# C 程序:计算等边三角形的面积 > 原文: [https://beginnersbook.com/2014/06/c-program-to-calculate-area-of-equilatral-triangle/](https://beginnersbook.com/2014/06/c-program-to-calculate-area-of-equilatral-triangle/) 等边三角形具有相等的边(所有三边相等)。在本教程中,我们共享了一个 C 程序,它将三角形边作为输入,将区域计算和显示为输出。 ## 计算面积的程序 为了计算等边三角形的面积,我们必须知道三角形的边。该程序将提示用户进入等边三角形的一边,并根据该值计算面积。 **程序中使用的公式**: `Area = sqrt(3)/4 * side * side` 这里`sqrt`表示“平方根”,这是`math.h`头文件的预定义函数。为了使用这个函数,我们在程序中包含了`math.h`头文件。 ```c #include<stdio.h> #include<math.h> int main() { int triangle_side; float triangle_area, temp_variable; //Ask user to input the length of the side printf("\nEnter the Side of the triangle:"); scanf("%d",&triangle_side); //Caluclate and display area of Equilateral Triangle temp_variable = sqrt(3) / 4 ; triangle_area = temp_variable * triangle_side * triangle_side ; printf("\nArea of Equilateral Triangle is: %f",triangle_area); return(0); } ``` 输出: ```c Enter the Side of the triangle: 2 Area of Equilateral Triangle is: 1.732051 ```