Program to check whether the given number is armstrong or not.
Algorithm:
Step 1: Read a number, num.
Step 2: Assign temp=num.
Step 3: Assign sum=0.
Step 4: Repeat steps 5,6&7 until temp=0 reaches.
Step 5: Compute digit=temp%10.
Step 6: Compute temp=temp/10.
Step 7: Compute sum=sum+(digit**3).
Step 8: If num==sum goto step 9 else goto step 10.
Step 9: Print num is an Armstrong number.
Step 10: Print num is not an Armstrong number.
Step 11: Stop
Flowchart:
Program code:
num=int(input('Enter any number '))
temp=num
sum=0
while temp>0:
digit=temp%10
temp=temp/10
sum=sum+(digit**3)
if num==sum:
print num,'is an Armstrong number'
else:
print num,'is not a Armstrong number'
temp=num
sum=0
while temp>0:
digit=temp%10
temp=temp/10
sum=sum+(digit**3)
if num==sum:
print num,'is an Armstrong number'
else:
print num,'is not a Armstrong number'
No comments