Home >Backend Development >C#.Net Tutorial >How to find the area of a triangle in c language
1. Analysis
Input three side lengths, apply Helen's formula to calculate the area, and output.
You can first determine whether a triangle can be formed, that is, the sum of any two sides is greater than the third side, and then calculate if a triangle can be formed, which can increase the rigor.
2. Implementation code
#include <stdio.h> #include <math.h> int main() { printf("请依次输入三个边长\n"); double a,b,c,p,s; scanf("%lf%lf%lf",&a,&b,&c); if(a+b>c && a+c>b && b+c>a) //判断是否可以构成三角形。 { p=(a+b+c)/2;//计算半周长 s=sqrt(p*(p-a)*(p-b)*(p-c));//套用海伦公式,计算面积 printf("面积为%lf\n", s);//输出结果 } else printf("无法构成三角形\n");//输入不合法,提示。 return 0; }
Recommended tutorial: c language tutorial
The above is the detailed content of How to find the area of a triangle in c language. For more information, please follow other related articles on the PHP Chinese website!