洛谷刷三角形面积时有一个结点报错了,找不到哪里的问题,有没有大姥帮忙看看
这是题目
这是报错
这是我第一次写的代码
#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
float a ,b , c , p , s;
scanf("%f %f %f", &a, &b, &c);
p = (a + b + c) / 2;
s = sqrt(p * (p - a) * (p - b) * (p - c));
printf("%.1f\n", s);
return 0;
}
我看到报错以后看了看题目以为是没有加边长限制,然后写了下面这个代码,结果还是不行,报错跟第一次一样
#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
float a ,b , c , p , s;
scanf("%f %f %f", &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("%.1f\n", s);
}
else
printf("三边长不符合要求");
return 0;
}