The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Programming Exercise 1: Area of a Circle
The area of a circle is pi * r2. Write a C program that inputs a single floating point numberrepresenting the value of the radius r. Input comes from standard input. Your program shouldoutput the area of the circle with a radius r. Now, the only problem is what value should you usefor pi? You have already worked with M_PI in Lab 6. In fact, inside of math.h is the followingline:
#define M_PI 3.14159265358979323846 /* pi */
so you need to include math.h and then use M_PI in an expression to calculate the area. Do nottype in this #define in your program, just include math.h. However, when compiling, withthe -ansi option you will need to add another option, otherwise things won’t go too well.
Try to build this program using:
gcc -ansi -pedantic -Wall assignment06pe01.c -o assignment06pe01
You should see that trouble exists. It will not recognize M_PI even though it is inside math.h.To get past this, you need to build the program by either dropping the -ansi option or by addingthe -D_GNU_SOURCE option. I prefer you choose the latter:
gcc -ansi -pedantic -Wall -D_GNU_SOURCE assignment06pe01.c -o assignment06pe01
You do not need to build the program with the -lm option since you are not missing anydefinitions from libm.a. You need to understand the previous sentence. Make certain that you dounderstand it. Do you?