Tuesday 13 February 2024

Class 11 CS Practical - 22

 

22 - Write a program in Python to input a number and determine whether the number is an Armstrong number or not.


n=int(input("Enter a number: "))

sum=0

k=n

while n>0:

    r=n%10

    n=n//10

    sum=sum+r*r*r

 

if(sum==k):

    print(k, "is a armstrong number")

else:

    print(k, "is not a armstrong number")


Output:

Enter a number: 153
153 is a armstrong number

Enter a number: 147
147 is not a armstrong number



No comments:

Post a Comment