Computer Science, asked by pandeyranjita1, 9 months ago

Write a program to check whether a number is perfect number or not using while loop

Answers

Answered by Anonymous
3

Answer:

hi....its a python program...

Explanation:

n = int(input("enter a number: "))

i = 1

sum = 0

while(i <n):

   if(n % i == 0):

       sum = sum + i

   i = i + 1

if (sum ==n):

   print("the number entered is a perfect number")

else:

   print(" the number entered is not a  perfect number")

hope it helps you

please mark brainliest

Answered by SƬᏗᏒᏇᏗƦƦᎥᎧƦ
87

Cod_e walkthrough is as follows:

Line 8 : Initialises an accumulator variable sum.

Line 9 : Initialises a counter variable i .

Line 16-17 : If the counter is a factor of num then add it to the accumulator.

Line 21 : Repeats the loop until i <=num/2. This will ensure that the number itself is excluded from the factor list.

Line 23 : If the sum of all its factors (excluding the number itself) is equal to the number then it is a Perfect number.

Output

Enter an integer

496

496 is a Perfect number

Output

Enter an integer

625

625 is NOT a perfect number

Attachments:
Similar questions