TASK-
Write a Python Program For Armstrong number:
Note: If sum of cubes of each digit of the number is equal to the number itself, then the number is called an Armstrong number. For example, 153 = ( 1 * 1 * 1 ) + ( 5 * 5 * 5 ) +
( 3 * 3 * 3 )
LOGIC BUILDING:
- Take input from user.
- Apply an algorithm which separates the digit of number and and add cube of each.
- Compare it with the original one.
- If it is same as original print its Armstrong else its not Armstrong.
CODE:
num=int(input("Enter the number: "))
original=num
sum=0
while(num!=0):
#getting last digit
d=num%10
#making sum
sum+=d**3
num//=10 # // gives integer answer and / gives float(decimal)
if (original==sum):
print("\nIt is an Armstrong Number")
else:
print("\nIt is Not an Armstrong Number")
OUTPUT:
Enter the number: 153
It is an Armstrong Number