Write a C program to demonstrate #define

0

Here is an example C program that demonstrates how to use the #define directive to define a constant:

In this program, the #define directive is used to define a constant called PI with the value of 3.14159. This constant is then used in the main() function to calculate the circumference of a circle with a given radius. The printf() function is used to output the result of this calculation.


When the program is compiled and run, the output should be:

The circumference of a circle with radius 5.000000 is 31.415900

Note that in this program, the #define directive is used to define a constant with a name and a value. Whenever the name PI appears in the program, the compiler will replace it with the value 3.14159. This can make the program more readable and easier to maintain, since it avoids hard-coding values throughout the code.

Post a Comment

0Comments
Post a Comment (0)