c++ program to check whether a given number is a perfect number or not

Write a c++ program to check whether a given number is a perfect number or not.

Flowchart of perfect number program

Flowchart of perfect number program in C++

C++ Source code of the perfect number

Output

enter the num 5

5 is a perfect number

Excercise

Find the possible mistakes in the following Shamil’s Flow Table of the program to check whether a given number is a perfect number or not.

 

loop

 

Line which executed

 

Actual work to  do

 

I=1

 

1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,

13, 14, 25, 16

N%i==0

6%1==0

Sum=sum+i

Sum=0+1=1

 

I=2

1, 2, 3, 4, 5, 6, 7, 8, 9, 10,

11, 12, 13, 14, 25,16,17,

11,12,13,14,25,16,

 

N%i==0

6%2==0

Sum=sum+i

Sum=1+2=3

I=3

 

1, 2, 3, 4, 5, 6, 7, 8, 9, 10,

11, 12, 13, 14, 25,16,17,

11,12,13,14,25,

16,17,11,12,13,14,25,16,

 

N%i==0

6%3==0

Sum=sum+i

Sum=3+3=6

I=4

 

1, 2, 3, 4, 5, 6, 7, 8, 9, 10,

11, 12, 13, 14, 25,16,17,

11,12,13,14,25,

16,17,11,12,13,14,25,16,17,18

 

 

 
  1, 2, 3, 4, 5, 6, 7, 8, 9, 10,

11, 12, 13, 14, 25,16,17,11,

12,13,14,25,

16,17,11,12,13,14,25,16,17,

18,19,20,21,26,27

 

Sum=6

Is a perfect number

Latest posts by Prof. Fazal Rehman Shamil (see all)

Buy advertisement space on T4Tutorials

For more details email [email protected]