c语言直角三角形面积错误

如题所述

这是是输入三边长用海伦公式求面积的:

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

int main()
{
double a, b, c, d, s;
printf("输入三条边的长:");
scanf("%lf%lf%lf", &a, &b, &c);
if(!(a+b > c && a+c > b && b+c > a)) {
puts("不能构成三角形!");
return 0;
}
d = (a+b+c)/2;
s = sqrt(d*(d-a)*(d-b)*(d-c));
printf("面积为:%.2g\n", s);
return 0;
}

这个是输入两直角边求面积的:

#include <stdio.h>

int main()
{
double a, b;
printf("输入2直角边的长:");
scanf("%lf%lf", &a, &b);
printf("面积为:%.2g\n", a*b/2);
return 0;
}
温馨提示:答案为网友推荐,仅供参考
相似回答