Back to DFS's C Page


OAC Problem Set I

For Loops
Due 15 Oct 99

You are to write a program which will produce a table of Olympic competition running distances in meters, kilometers, yards, and miles for all distances which are specified in three digits for meters, i.e.,

You should make your program as efficient as possible using a for loop by exploiting the pattern exhibited in the distances. (N.B. 1 meter = 0.001 kilometers = 1.094 yards = 0.0006215 miles)

Input Specification: No user input is needed. A variable called meters should be initialized to 100 and the other values should be generated by the header of the for loop.

Output Specification: Print the results to the screen in the following manner:

  Table of 3-Digit Olympic Running Distances
==============================================
   Meters    Kilometers     Yards     Miles
      100          ----      ----      ----
      200          ----      ----      ----
      400          ----      ----      ----
      800          ----      ----      ----

The data in each column should be right justified and be given to four decimal places.


Adapted from a University of Guelph computer problem.
Posted: 13 Oct 1999
© DFStermole 1999