A perfect number is a number that is the sum of all of its divisors greater than one. That is, it is the sum of all the numbers less than itself which divide into it without a remainder. 6 is a perfect number because its divisors are 1, 2,  and 3 and the sum of those divisors is 6.Write pseudocode to display the first three perfect numbers.

What will be an ideal response?


num perfects = 0
num current = 2
num sum = 0

while perfects < 3
  sum = 0
  for num x = 1 to current - 1
    if current mod x = 0
      sum = sum + current
 endfor
  if sum = current
    print current
    perfects = perfects + 1
  endif
  current = current + 1
endwhile

Computer Science & Information Technology

You might also like to view...

A set procedure, called the order of calculations, determines the order in which operations in a formula with multiple operators will be evaluated

Indicate whether the statement is true or false

Computer Science & Information Technology

Creating relationships is not an effective way to test your normalization.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

When a variable ceases to exist at the end of a method, programmers say the variable ____.

A. is undeclared B. is out of memory range C. goes out of scope D. is lost

Computer Science & Information Technology

The ____ box in the dialog box in the accompanying figure allows you to create alternative text to be used by screen readers.


a. URL
b. Target
c. Slice Type
d. Alt Tag

Computer Science & Information Technology