How to use the macro definition of c language to calculate the triangle area
This article mainly explains "how to use the macro definition of c language to find the triangle area". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to use the c language macro definition to find the triangle area"!
Macro definition exercise to find the triangle area
1. Topic description
The area of the triangle = SQRT (S * (Smura) * (Smurb) * (SMEC)) where S = (a+b+c) / 2Magi a, b, c are the three sides of the triangle. Define two macros with parameters, one for area and the other for S. Write a program in which the macro name with arguments is used to calculate the area area.
two。 Format and sample
Input format
The three sides of an a b c triangle, which can be decimals.
Output format
Triangle area, keeping 3 decimal places.
Sample input
3 4 5
Sample output
6.000
3. Reference answer 1#include
2#include
3#define s (a _ r _ b _ m _ c) (a+b+c) / 2
4#define area (a _ r _ r _ b _ r _ r _ r s) sqrt (s * (m _ Meia) * (m _ Meib) * (m _ Mel c))
5int main ()
6 {
7float x,y,z
8scanf ("% f%f%f", & X.
9printf ("% .3f", area (x _ mae _ r _ r _ z _ r _ s (x _ menery _ z)
10return 0
11} at this point, I believe you have a deeper understanding of "how to use the c language macro definition to find the triangle area". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!