三角形面积为area=sqrt(s*(s-a)*(s-b)*(s-c)),其中s=0.5(a+b+c).a,b,c为三角形的三条边

2024-12-23 01:02:36
推荐回答(3个)
回答1:

#include
#include
#define s(a,b,c) ((a+b+c)/2)
#define area(a,b,c) sqrt(s(a,b,c)*(s(a,b,c)-a)*(s(a,b,c)-b)*(s(a,b,c)-c))
void main()
{
float a,b,c;
scanf("%f,%f,%f\n",&a,&b,&c);
if (a+b>c&&a+c>b&&b+c>a)
printf("%f\n",area(a,b,c));
else
printf("此三边不够成三角形!\n");
}
上面是在VC++6.0中调试的
输入数字时用逗号隔开

回答2:

#define s((a), (b), (c)) \
(((a) + (b) + (c)) / 2)
#define area((a),(b),(c)) \
sqrt(s((a), (b), (c)) * \
(s((a), (b), (c))-(a)) * \
(s((a), (b), (c))-(b)) * \
(s((a), (b), (c))-(c)))

回答3:

#define s(a,b,c) 0.5*(a+b+c)
#define area(s,a,b,c) sqrt(s*(s-a)*(s-b)*(s-c))
#include
main()
{int a,b,c;
float s;
printf("put a,b,c=?\n");
scanf("%d%d%d",&a,&b,&c);
s=s(a,b,c);
printf("The area is:%.2f\n",area(s,a,b,c));
}