CSCI 116
Project #3: Biggest and
Smallest
Purpose: To use some selection statements to
find the biggest and smallest of a list of numbers.
Program objective: Your program is to read a 10 numbers from the keyboard
and to print out the biggest and smallest of them.
Instructions:
Write a program that asks the user to enter 10 numbers. It should read the 10 numbers in, and the
print out the biggest and the smallest numbers read. After printing out the results, your program
should exit normally. Your program can
use if statements, but should not use loops or arrays. Here is some sample output:
Enter 10 numbers: 1
10 100 20 50 77 95 145 86 32
The smallest number
was 1 and the largest number was 145
Press any key to
continue
To find the
largest number, let’s think about reading them in one at a time. The first number read is the largest number
seen so far, since it’s the ONLY number seen so far. Now, every time we get a new number we can
compare it to the current largest number.
If it is bigger, it becomes the new largest number—otherwise, the
previous largest number is still the biggest.
We do that until we have seen the last number, and at that point the
biggest number is the largest of all of them.
We do a similar process for the smallest number.
That should
about cover it…have fun!