integers assume

advertisement
Exercises
1) Write a program that finds the smallest of several integers. Assume that the first value read specifies
the number of values remaining. Use for Loop
2) Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of
several tankful of gasoline by recording miles driven and gallons used for each tankful. Develop a
program that will 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
tankful. 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
Enter the gallons used (-1 to end): 10.3
Enter the miles driven: 200
The miles / gallon for this tank was 19.417475
Enter the gallons used (-1 to end): 5
Enter the miles driven: 120
The miles / gallon for this tank was 24.000000
Enter the gallons used (-1 to end): -1
The overall average miles/gallon was 21.601423
3) The process of finding the largest number (i.e., the maximum of a group of numbers) is used
frequently in computer applications. For example, a program that determines the winner of a sales
contest would input the number of units sold by each salesperson. The salesperson who sells the most
units wins the contest. Write a pseudocode program and then a program that inputs a series of 10
numbers, and determines and prints the largest of the numbers.
[Hint: Your program should use three variables as follows]:
Counter: A counter to count to 10 (i.e., to keep track of how many numbers have been input and to
determine when all 10 numbers have been processed)
Number: The current number input to the program
Largest: The largest number found so far.
4) Solve q3 with do…while
Download