Title: Check whether the given number is
Armstrong or not
11=1
21=2
71=7
153=13+53+33=1+125+27=153
The above all are Armstrong number
23=22+32=4+9=13 [23 is not armstrong]
Program:
n=int(input("Enter n value\n"))
r=0
t=n
c=0
while(t>0):
c=c+1
t=t//10
t=n
while(t>0):
p=1
for i in range(1,c+1):
p=p*(t%10)
r=r+p
t=t//10
if(n==r):
print(n,' is armstrong')
else:
print(n,' is not armstrong')
Output:
>>>
Enter n value
153
153 is
armstrong
>>>
Enter n value
4
4 is
armstrong
>>>
Enter n value
23
23 is
not armstrong
Comments
Post a Comment