Tuesday, 13 February 2024

Class 11 CS Practical - 23

 

23 - Write a program in Python to print all Armstrong numbers from 0 to 10000.


for n in range(0,10001):

    sum=0

    k=n

    while n>0:

        r=n%10

        n=n//10

        sum=sum+r*r*r

 

    if(sum==k):

        print(k,end=" ")


Output:

0 1 153 370 371 407 

No comments:

Post a Comment