Advertisements
Advertisements
Question
Write a program to input any number and check whether given number is Armstrong or not.
Code Writing
Advertisements
Solution
For a three-digit Armstrong number, add the cubes of its digits and compare the sum with the original number.
n = int(input("Enter any number: "))
original = n
sum_of_cubes = 0
while n > 0:
digit = n % 10
sum_of_cubes += digit ** 3
n //= 10
if sum_of_cubes == original:
print("Armstrong number")
else:
print("Not an Armstrong number")
shaalaa.com
Is there an error in this question or solution?
