因为你定义的都是整型变量,而你里面做了除法,当然会出问题,把变量改成实数型就没问题了必须输出1.0 只输出1 不管杂的结果为0 原因如果是l=1.0/2(a+b+c)结果为实型数,而l=1/2(a+b+c)结果为整形,四舍五入就为零了劳资的是对的,运行成功的,但是为什么要1.0/2啊,如果1/2,就结果为0啊!!!#include
#include
main()
{
float a,b,c,l,s;
printf("please input a,b,c:");
scanf("%f,%f,%f",&a,&b,&c);
if (((a+b)>c)&&((a+c)>b)&&((b+c)>a))
{
l=1.0/2*(a+b+c);
s=sqrt(l*((l-a)*(l-b)*(l-c)));
printf("s=%f",s);
}
else
printf("NO!"); }#include
#include
main()
{
float a,b,c,l,s;
printf("please input a,b,c:");
scanf("%f,%f,%f",&a,&b,&c);
if (((a+b)>c)&&((a+c)>b)&&((b+c)>a))
{
l=1.0/2*(a+b+c);
s=sqrt(l*((l-a)*(l-b)*(l-c)));
printf("s=%f",s);
}
else
printf("NO!"); }