12.010 Lecture 08 Exercises.

In this section, we test and evaluate some of the basic C concepts.


253 6430

Exercise 1.


Start with program hello.c. This program simply performs IO to print out a character string and the standard values of various numerical parameters from the C library.

To compile the program use the command

cc hello.c

To run the program use


Now edit the program to stop the header file math.h from being included e.g.
/* #include  <math.h> */
and recompile the code. What happens?

Look in the math.h header file (/usr/include/math.h). Try printing out some of the
other mathematical constants. Printout value for five different constants. What values do they have?

Exercise 2.

When program area.c is invoked as follows

a.out 2.3

it is supposed to calculate the area of a circle with radius 2.3. However, when you
compile and run the program it will print out 0. as the area of the circle. What is wrong how can it be fixed?

Secondly, modify area.c so that it can take if several radii and write one line
of out for each value stating the radius and the area of the circle with that area.