Gonna have lots of trouble with school if you won't even try stuff.
• finds and prints all the perfect numbers between 1 and a random number between 50 and 100.
|
1) Generate a random number.
2) Loop from 1 to that random number.
• uses a function isPerfect that determines whether parameter number is a perfect number.
|
3) Write a method isPerfect that takes a number as an argument and returns a boolean.
4) Loop through all numbers from 1 to (argument-1) to check if they are divisors.
5) To check if something is a divisor, use the modulo operator to look for left overs after division.
6) Keep a tally of the divisors.
7) When the loop is done, check the tally. If it is the same number as the argument, return true.
• prints the divisors of each perfect number to confirm that the number is indeed perfect
|
8) Pass a vector pointer to isPerfect by adding it as a second arg.
9) Add code to the loop that will add each divisor to the vector.
10) Use printf to print the divisors when isPerfect returns true.
If you try, you will learn a lot faster. Mistakes can be frustrating, but they are a valuable tool when learning. Let me know if any of the steps confuse you.