求三角形面积定义两个带参宏,一个用来求s,另一个用来求area。编写程序,在程序中用带参宏的宏名来求面积

已知三边a,b,c;
2024-12-19 10:38:41
推荐回答(2个)
回答1:

include
#include
#define S (a+b+c)/2
#define AREA(a,b,c) sqrt(S*(S-a)*(S-b)*(S-c))
main()
{
float a,b,c;
printf("Please input the rim lengthes of the triangle:\n");
scanf("%f%f%f",&a,&b,&c);
printf("The area of the triangle is %-5.2f.\n",AREA(a,b,c));
}

回答2:

#include
#include
#define k(a,b,c) ((a+b+c)/2)
#define area(l,a,b,c) sqrt(l*(l-a)*(l-b)*(l-c))
main()
{float x,y,z,S,AREA;x=3;y=4;z=5;
S=k(x,y,z);
AREA=area(S,x,y,z);
printf("%0.2f\t%0.2f\n",S,AREA);

}