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

By: Prof. Dr. Fazal Rehman | Last updated: October 21, 2023

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

Leave a Comment

All Copyrights Reserved 2025 Reserved by T4Tutorials