输入三角形的三条边长,计算并输出三角形的面积。C语言程序设计,我是这样做的,请大家看看有什么问题
来源:百度知道 编辑:UC知道 时间:2024/07/07 20:28:33
#include <stdio.h>
main()
{int a,b,c,p,s;
a=3;
b=4;
c=5;
p=(a+b+c)/2;
s=sqrt(p*(p-a)*(p-c)*(p-b));
printf("%d\n",s);
}
main()
{int a,b,c,p,s;
a=3;
b=4;
c=5;
p=(a+b+c)/2;
s=sqrt(p*(p-a)*(p-c)*(p-b));
printf("%d\n",s);
}
这样不行的
你这数据全是int的了,结果肯定出入很大
#include <stdio.h>
main()
{int a,b,c;
float p,s;//改成float
a=3;
b=4;
c=5;
p=(a+b+c)/2;
s=sqrt(p*(p-a)*(p-c)*(p-b));
printf("%lf\n",s);//改成float
}