Question: A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. For instance, 6 has

A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. For instance, 6 has divisors 1, 2 and 3 (excluding itself), and 1 + 2 + 3 = 6, so 6 is a perfect number. See this website for more details.

In either C++, Java, C#, or Python, develop a program that performs the following functionality:

1) Create a function that does the hard work of determining "perfect number-ness"

  • The one input parameter is an integer value which is the number value to test (Let's call it n)
  • Sum up all the divisors of the number from 1 to n-1 (Let's call it sum)
  • Return a boolean flag which indicates if the sum is equal to the test number (n equals sum)

2) In the main function, print all the perfect numbers from 1 to 10000

  • Create a loop that iterates from values 1 to 10000
  • For each iteration, call the function and use its result accordingly
  • No user input is required or allowed
  • 6, 28, 496, and 8128 are the only four values which are perfect numbers

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!