Title: Display Armstrong numbers up to specified
number
Program:
n=int(input("Enter n value\n"))
for j in range(1,n+1):
t=j
c=0
r=0
while(t>0):
c=c+1
t=t//10
t=j
while(t>0):
p=1
for i in range(1,c+1):
p=p*(t%10)
r=r+p
t=t//10
if(j==r):
print(j)
Output:
Enter n value
1000
1
2
3
4
5
6
7
8
9
153
370
371
407
Comments
Post a Comment