> 其他 >
C++ 编程 关于用海伦公式计算三角形面积的一个程序
#include
void main ()
{
int a,b,c,s,area,d;
scanf("%d%d%d",&a,&b,&c);
s=(a+b+c)/2;
d=s*(s-a)*(s-b)*(s-c);
area=sqrt(d);
if (a+b>c,b+c>a,a+c>b)
printf("三角形面积=%d\n",area);
else printf("无法构成三角形\n");
}
我是初学者,刚刚接触,编的程序是错误的,错误一是sqrt公式那里的运用,还有就是总是说找不到与else对应的if.
人气:256 ℃ 时间:2019-08-20 18:37:23
解答
#include
#include
void main ()
{
float a,b,c,d;
float s;
double area;
scanf("%f%f%f",&a,&b,&c);
if (a+b>c&&b+c>a&&a+c>b)//&&代表逻辑和
{
s=(a+b+c)/2;
d=s*(s-a)*(s-b)*(s-c);
area=sqrt(d);
printf("三角形面积=%d\n",area);
}
else
{
printf("无法构成三角形\n");
}
}
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版