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 that are greater than 1.
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.
You need to write 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 sum. 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 to test for equality.
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. Read the following documents for help on how to write your program.
// Your name here // CSCI 2611 programming assignment 1, submission 1 // Today's date here //---------------------------------------------------------- // This program reads a number from the user and tells the // user whether that number is perfect. // // A number n is perfect if the sum of the proper divisors of n is n. // For example, 6 is perfect since the proper divisors of 6 // are 1, 2 and 3, and 6 = 1 + 2 + 3. //----------------------------------------------------------- #include <iostream.h> int main() { int n,k,sum; //--------------------------------- // Read the number into variable n. //--------------------------------- cout << "What number should I test?" << endl; cin >> n; //---------------------------- // Test whether n is perfect. //---------------------------- sum = 0; k = 1; -- You will need to supply this part. Erase these three lines and write -- loop that accumulates, in variable sum, the sum of the proper -- divisors of n. Use k as a counter. //------------------- // Report the answer. //------------------- if(sum == n) { cout << n << " is perfect" << endl; } else { cout << n << " is not perfect" << endl; } return 0; }