Question
PROG 110: The programming language is C# // write a program that finds all the perfect numbers between 2 and 500 // A perfect number
PROG 110: The programming language is C#
// write a program that finds all the perfect numbers between 2 and 500 // A perfect number is a number if // it equals the SUM of the set of SMALLER numbers, including 1, that divide evenly into it. // you need an outer loop that cycles from 2 to 500, this counter represents // each of the numbers from 2 to 500 that you want to examine and decide if it is perfect // inside that loop, you determine if that currentNumber is a perfect one // start with a int total = 0; // then create an inside loop which loops from 1 to that currentNumber // inside this second loop, determine if the inside loop counter // divides into the currentNumber (the outside loop counter) evenly. // you will need to use the % operator. // if it does divide evenly, add it to the total. // after you leave the inside loop, compare your total to the currentNumber // if they are equal, write a message like this // ******* {currentNumber} ******* is a perfect number. Hints: - there are 3 perfect numbers between 2 and 500 - we are excluding 1 as not perfect number since you can't divide any number by 0 - do not name you loop counters i and j, that makes the code too hard to read, give them very meaningful names If your outside loop was at 28, then you inside loop would add 1 2 4 7 14 to your total, and then when you leave the inside loop, the bottom of the outside loop would compare that total, 28, to the current outside loop counter, 28, and since they are equal, it would write out ******* 28 ******* is a perfect number.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started