Due January 31, 2000.
Problem: The Top Two
Write a program which prints out the highest two (positive) integers which the user has typed in. The user should be able to input a sequence of positive integers separated by carriage returns, terminated by a negative integer.
Here's a sample interaction with my program:
Enter some numbers: 3 2 6 10 1 -8 The two highest numbers were 10 and 6.
Problem: Printing a grid
Perhaps at some point in your life, you could have more or less been characterized by the following two properties: (a) you were in the computer lab late at night, (b) you were in dire need of graph paper.
Thanks to the program you are about to write, in the future you shall be capable of producing your own graph paper (albeit of rather mediocre quality).
Write a program that accepts a height and a width (both assumed to be >= 1) as input and outputs a grid using the "+", "-", and "|" characters. (Note: If you can't find or don't have these three characters on your keyboard, you may substitute any others - but you must use three distinct characters.)
Here's a sample interaction with my program; your program should give identical output.
Enter height: 3 Enter width: 2 +-+-+ | | | +-+-+ | | | +-+-+ | | | +-+-+Here's another example.
Enter height: 1 Enter width: 4 +-+-+-+-+ | | | | | +-+-+-+-+
Try to make your program as uncomplicated as possible!
Problem: Too perfect for friends
A number is called perfect if the sum of its proper positive divisors sum up to the number itself.
(Terminology: d is a divisor of a
postiive number n if n yields a remainder of 0 when divided by d.
d is a proper divisor of n if d < n and d is a divisor of n.)
For example, 28 is perfect, as
28 = 1 + 2 + 4 + 7 + 14.
Two numbers a and b are called amicable if the sum of the proper positive divisors of one is equal to the other, and vice-versa. For example, the proper positive divisors of 220 add up to 284:
284 = 1+2+4+5+10+11+20+22+44+55+110
and, the proper positive divisors of 284 add up to 220:
220 = 1+2+4+71+142
Hence, 220 and 284 are amicable.
Write a program which expects as input a positive integer n, and then prints out all perfect numbers and pairs of amicable numbers in the range 1. . . n. A pair of amicable numbers should be printed out only once, and only if both of the numbers are in the range 1 . . . n.
Here's a sample interaction with my program:
Enter a number: 284 6 is perfect. 28 is perfect. 220 and 284 are amicable - how cute!