Question

Use a preprocessor directive to define the value of PI (π), then calculate the area of...

Use a preprocessor directive to define the value of PI (π), then calculate the area of a circle using PI, given any radius value (r).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The pre-processor processes our program before going to the compiler. It begins with a hash symbol (#).

I'm using C++ to write the program.

#include<iostream>
using namespace std;
//using preprocessor directive for defining value of PI
#define PI 3.141926
#include<math.h> // for finding power of a number
int main(){
float r, Area;
cout<<"Enter Radius of the circle: ";
cin>>r;
Area= PI* pow(r, 2); // pow(r,2)== r^2
cout<<"Area of the circle is: "<< Area;
return 0;
}

Output:

In this program we are defining the value of PI using "define" preprocessor directive. After taking input value for radius (r) i've calculated Area. Finally i'm printing the Area

Add a comment
Know the answer?
Add Answer to:
Use a preprocessor directive to define the value of PI (π), then calculate the area of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT