March 5, 2005
     

Program / Task Name:

   Perfect Number

Level:

 

 Novice / Advanced

Point Value:

 

 3

Solution(s):

 

 prob03.c

Data File(s):

 

 

 
C programmers: your program name must be: prob03.exe
JAVA programmers: your program name must be: prob03.class

 

Task Description

A positive integer is said to be a perfect number if it is equal to the sum of its positive divisors less than itself. For example, 28 is perfect, because

28 = 1 + 2 + 4 + 7 + 14

On the other hand, 12 is not perfect, because

12 <> 1 + 2 + 3 + 4 + 6

You are to write a program that prompts the user to enter a positive integer and responds by reporting whether or not the given number is perfect. The program should terminate when the user enters 0.

 

Program Input / Output

 

Enter a positive integer: 12

12 IS NOT perfect.

 

Enter a positive integer: 28

28 IS perfect.

 

Enter a positive integer: 0

 

 

   
  (c) 2005 Hewlett-Packard Company