Topic 1038: [Introduction to Programming] Macro Definition Exercise: Area of Triangle

Area of ​​triangle = SQRT(S*(Sa)*(Sb)*(Sc)) where S=(a+b+c)/2, a, b, c are the three sides of the triangle. Define two macros with parameters, one is used to find area, and the other macro is used to find S. Write a program and use the macro name with actual parameters to find the area.

Input format

The three sides of triangle abc can be decimals.

Output format

Area of ​​a triangle to 3 decimal places

Sample input

copy

3 4 5

Sample output

copy

6.000

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
#define GetS(a,b,c) ((a+b+c)/2.0)
#define GetArea(a,b,c){\
      float S=GetS(a,b,c);\
      float area=sqrt(S*(S-a)*(S-b)*(S-c));\
      cout << fixed << setprecision(3) << area;\
}

/*这个"\"放在宏定义函数句子的末尾,表示本句结束,以及其他*/
int main() {
    float a, b, c;
    cin >> a >> b >> c;
    GetArea(a,b,c);
   


    return 0;
}

Guess you like

Origin blog.csdn.net/qq_63999224/article/details/132359800