Professional Documents
Culture Documents
Lab 3
Lab 3
Lab Exercises 3.
1. (Gas Mileage) Drivers are concerned with the mileage obtained by their
automobiles. One driver has kept track of several tankfuls of gasoline by recording
miles driven and gallons used for each tankful. Develop a program that uses scanf
to input the miles driven and gallons used for each tankful. The program should
calculate and display the miles per gallon obtained for each tankful. After
processing all input information, the program should calculate and print the
combined miles per gallon obtained for all tankfuls. Here is a sample input/output
dialog:
Enter the gallons used (-1 to end): 12.8
Enter the miles driven: 287
The miles/gallon for this tank was 22.421875
2. (How Fast Is Your Computer?) How can you determine how fast your own
computer operates? Write a program with a while loop that counts from 1 to
1,000,000,000, incrementing by 1 during each iteration of the loop. Every time the
count reaches a multiple of 100,000,000, print that number on the screen. Use your
watch to time how long each 100 million iterations of the loop takes. [Hint: Use the
remainder operator to recognize each time the counter reaches a multiple of
100,000,000.]
3. (Tabular Output) Write a program that uses looping to print the following table of
values. Use the tab escape sequence, \t, in the printf statement to separate the
columns with tabs.
N 10*N 100*N 1000*N
1 10 100 1000
2 20 200 2000
3 30 300 3000
4 40 400 4000
5 50 500 5000
6 60 600 6000
7 70 700 7000
8 80 800 8000
9 90 900 9000
10 100 1000 10000