ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 11 May 2017 My Price 9.00

Programming Exercise 1: Area of a Circle

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?

Answers

(11)
Status NEW Posted 11 May 2017 07:05 AM My Price 9.00

-----------

Not Rated(0)