Do the following exercises in C. Make sure that you save the file as .c not .C, and compile using gcc instead of g++. You will find that the gcc compiler is faster and that your executable code takes up less space.


Exercise #1

Write a program that computes the volume of any planet in cubic kilometers. Have the volume computation performed by a function named sphere. Arrange to provide the radius of the planet at run time.
Hint: Volume of sphere is 4/3 * pi * r * r * r

To test your program, try these radii values:

Earth's radius    =  6378.2 km
Jupiter's radius  =  71492 km
Venus' raduius    =  6051.8 km





Exercise #2

The energy of a moving mass is given by the formula 1/2 * m * v * v. Write a program that determines the energy ratio of a car moving at two speeds provided at run time. Write and use a function named square to calculate the square of v. Also, write and use a function named energy to calculate the energy of a car. Use your program to determine how much more energy a car has when moving at 80 miles per hour than when it is moving at 55 miles per hour. Prompt the user for the mass of the vehicle and the two velocities to be compared.














Exercise #3

Array exercise

mean
- average of all the values
variance
- average of the squared distances between each value and the mean
standard deviation
- square root of the variance