原文: 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头文件。
#include<stdio.h>#include<math.h>int main(){int triangle_side;float triangle_area, temp_variable;//Ask user to input the length of the sideprintf("\nEnter the Side of the triangle:");scanf("%d",&triangle_side);//Caluclate and display area of Equilateral Triangletemp_variable = sqrt(3) / 4 ;triangle_area = temp_variable * triangle_side * triangle_side ;printf("\nArea of Equilateral Triangle is: %f",triangle_area);return(0);}
输出:
Enter the Side of the triangle: 2Area of Equilateral Triangle is: 1.732051
