(adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-2960223314593660", enable_page_level_ads: true }); Python program to print all armstrong numbers between 1 to n. - TecGlance

Header Ads

Python program to print all armstrong numbers between 1 to n.

Algorithm:::



Step 1: Start
Step 2: Read limit of number, n
Step 3: Repeat steps 4-11 until num=n+1
Step 4: Assign sum=0
Step 5: Assign temp=num
Step 6: Repeat steps 7,8&9 until temp=0 reaches
Step 7: Compute digit=temp%10
Step 8: Compute sum=sum+(digit**3)
Step 9: Compute temp=temp/10
Step 10: if num==sum goto step 11
Step 11: Print num
Step 12: Stop


Flowchart:::


Program code:::

n=int(input('Enter the upper limit '))
for num in range (1,n+1):
    sum=0
    temp=num
    while temp>0:
        digit=temp%10
        sum=sum+(digit**3)
        temp=temp/10
    if num==sum:
        print num
   
   

No comments

Powered by Blogger.