(adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-2960223314593660", enable_page_level_ads: true }); Program to check a number is perfect number or not. - TecGlance

Header Ads

Program to check a number is perfect number or not.

Algorithm:
Step 1: Start
Step 2: Read a number, num

Step 3: Assign i=1

Step 4: Assign sum=0

Step 5: Repeat steps 6,7&8 until i=num reaches

Step 6: If num%i==0 goto step 7

Step 7: Compute sum=sum+i

Step 8: Compute i=i+1

Step 9: If sum==num goto step 10 or else goto step 11

Step 10: Print num is a perfect number

Step 11: Print num is not a perfect number

Step 12: Stop

Flowchart:


Program code:
num=int(input('Enter a number '))
i=1
sum=0
while i<num:
    if num%i==0:
        sum=sum+i
    i=i+1
if sum==num:
    print num,'is a perfect number'
else:
    print num,'is not a perfect number'

No comments

Powered by Blogger.