Work on these exercises individually, but be quick to get help as needed from your student assistants, your instructor and your classmates.
A perfect number is a number that equals the sum of its factors that are smaller than itself (including 1).
int factorsOfN(int n, int factors[])that puts into the given array all the factors of n, including 1 but not including n itself. The function should return the number of factors it put into the array.
Test your function by calling it from main with appropriate arguments and printing the results.
int isPerfect(int n)that returns
1
if n
is perfect and 0
if it is not perfect.
Do not attempt to find a closed-form solution. Instead, use your factorsOfN function to compute the factors of n, and then sum those factors and compare the sum to n.
Test your function by calling it from main with appropriate arguments and printing the results.
int printPerfect(int m)that prints all the perfect numbers less than or equal to m and returns the number of such perfect numbers.
6 28 496 8128and return 4.
Test your function by calling it from main with appropriate arguments.
int askPerfect()that repeatedly asks the user for a number, checks it for perfection, and prints an appropriate response, until the user enters -1 to quit. You do NOT have to deal with bad inputs (like 4.3 or do 10 pushups).
A sample run of this part of the program might be:
Enter an integer (negative to quit): 6 6 is perfect. Enter an integer (negative to quit): 24 24 is not perfect. Enter an integer (negative to quit): 28 28 is perfect. Enter an integer (negative to quit): -1 Goodbye!
Test your function by calling it from main and entering appropriate inputs.