22Comparing Numbers

Comparing one input to a known value is common enough, but you’ll often need to process a collection of inputs.

Write a program that asks for three numbers. Check first to see that all numbers are different. If they’re not different, then exit the program. Otherwise, display the largest number of the three.

Example Output

 
Enter the first number: 1
 
Enter the second number: 51
 
Enter the third number: 2
 
The largest number is 51.

Constraint

  • Write the algorithm manually. Don’t use a built-in function for finding the largest number in a list.

Challenges

  • Modify the program so that all entered values are tracked and the user is prevented from entering a number that’s already been entered.

  • Modify the program so that it asks for ten ...

Get Exercises for Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.