需求:

编程输入三角形的边长,求三角形面积.
已知三角形的面积公式为:面积=sqrt(s * (s-a)(s-b)(s-c)),s = (a + b +c)/2)

C语言代码

#include <stdio.h>#include<math.h>

int main(void) {
float a, b, c;
printf("请输入三角形的边长:\n");fflush(stdout);
printf("a=");fflush(stdout);
scanf("%f", &a);
printf("b=");fflush(stdout);
scanf("%f", &b);
printf("c=");fflush(stdout);
scanf("%f", &c);

float s;
float s1;
s = (a + b +c)/2;
s1 = sqrt(s * (s-a) *  (s-b) * (s-c));
printf("三角形的面积 = %f", s1);
return 0;
}
[1]: https://image.wuquejs.cn/o_1e2scaqep15bh4fr53p1h211c5ia.png

运行结果:

最后修改:2022 年 01 月 13 日 11 : 05 PM
如果觉得我的文章对你有用,请随意赞赏