使用海伦公式计算三角形的面积,当输入3个0时结束计算。
#include
#include
int main()
{
float a,b,c,s,l;//a,b,c为三角形的边长,s为面积
while(1)
{
scanf("%f %f %f",&a,&b,&c);
if(a==b&&b==c&&c==0) break;
if(a+b
{
l=(a+b+c)/2.0;
s=sqrt(l*(l-a)*(l-b)*(l-c));
printf("该三角形的面积为%.3f\n",s);
}
}
}
main()
{
double a,b,c,x,s;
scanf("%f,%f,%f",&a,&b,&c);
x=(a+b+c)/2;
s=sqrt(x*(x-a)*(x-b)*(x-c));
printf("%.2f\n",s);
}
结果保留2位小数