Class Work (CS 312) 22 Feb 2013

Problems with Loops

1. Write a program that prompts the user to enter a number and it prints out if that number is prime or not.
2. Write a program that prints all the prime numbers less than 1000.
3. A perfect number is equal to the sum of its divisors. 6 is a perfect number (6 = 1 + 2 + 3). Write a program that prompts the user to enter a number and it prints out if that number is perfect or not.
4. Write a program that prints all the perfect numbers less than 10000.
5. Write a program that prompts the user to enter a number and it prints the reverse of that number. For example, if the user entered 3489, your program will print 9843.

Challenge Problem

A software engineer lived on a street that was numbered linearly starting at 1. She had a dog that she used to take out for walks. In the morning she would walk in one direction and in the evening she would walk in the opposite direction. On one of her walks she summed the house numbers in that direction and compared it to the sum of the house numbers in the other direction (not including her house number). To her amazemment she found that the two sums were the same. This was a unique feature of her house and she felt that she lived in a lucky house. So when she moved to another city, she asked her realtor to find her a house with exactly that same feature, i.e. the sum of house numbers on one side is equal to sum of the house numbers on the other side. Your task is to write a program that will help the real estate agent find pairs of numbers (the lucky house and the last house on the street). Assume that there cannot be more than 10,000 houses on a given street. The first set of numbers that have this property is 6 and 8.