Computer Science 2611
Spring 2000
Laboratory Assignment 1

Terminology

For this assignment all numbers are positive integers.

Number k is a proper divisor of number n if k < n and k is a divisor of n. For example, 3 is a proper divisor of 6 and 5 is a proper divisor of 15. The number 1 is a proper divisor of all numbers.

A number n is perfect if the sum of the proper divisors of n is n. For example, the proper divisors of 6 are 1, 2 and 3. Since 1+2+3 = 6, 6 is a perfect number. Similarly, the proper divisors of 28 are 1, 2, 4, 7, and 14. Since 1+2+4+7+14 = 28, 28 is a perfect number.

Assignment

Write a C++ program that reads a number n from the user and tells whether n is perfect. It will need to have a loop that accumulates the sum of the proper divisors of n. Look at each number from 1 to n-1. For each one, if it is a divisor of n, add it into the total. In a C++ program you can test whether k is a divisor of n by testing whether n%k == 0. Be sure to use a double-equal.

Test your program. If it does not work, fix it. When it works, print it and hand it in. Be sure that your name is typed in your program as a comment.