#Python code to print the armstrong numbers in a given range
def armstrong(n):
m=n
digits=0
while m>0:
digits+=1
m/=10
m=n
N=0
while m>0:
N+=pow(m%10,digits)
m/=10
if n==N:
return 1
else:
return 0
for num in range(1000):
if armstrong(num+1)==1:
print num+1
def armstrong(n):
m=n
digits=0
while m>0:
digits+=1
m/=10
m=n
N=0
while m>0:
N+=pow(m%10,digits)
m/=10
if n==N:
return 1
else:
return 0
for num in range(1000):
if armstrong(num+1)==1:
print num+1
No comments:
Post a Comment