CS21 Spring 2005
Homework 2
Due Sunday, January 23 before 11:30pm


Answer the following Review Questions from the C book on your own, but do not turn them in. I will post answers on the CS21 web page next week.

Please complete the following 3 programs and turn them in using cs21handin. You should work on this assignment by yourself (no partners).

  1. Write a program that asks the user for the radius of a sphere, and then computes the volume of that sphere (V) using the formula:



    where pi is approximately 3.14159. Note: there is no "raise to a power" operator in C. Given the arithmetic operators from Chapter 2, how can you write an expression that achieves the desired result?

    Remember to print out a prompt to the user to enter the input values, and then to print out the result in a way that would make sense to a user of your program. For example, here is the output of my program when a user enters 2.3 as the radius:

    This is a program that computes the volume of a sphere given its radius.
    Enter the sphere's radius as a decimal:  2.3
    The volume of a sphere with radius 2.3 is  50.965 
    

  2. Write a program that asks the user to enter four numbers, and then computes the average of those four numbers.
  3. Write a program that converts a length in yards to the corresponding length in meters and centementers. For example, 2.3 yards = 2 m 10.312 cm. Your program should output the number of meters followed by 'm' and the number of centimeters followed by 'cm' as in the example above. The conversion factors you might need are:
         1 yard = 3 feet = 0.9144 meters
         1 meter = 100 centimeters
    

Please use the cs21handin command to turn in your homework.