Input a number and verify whether it is an Armstrong number or not. A number is called a Armstrong Number if the number is equal
to the sum of cube of each digit of the number. 153 = 1
3+53+33 = 1+125+27
Answers
Answered by
2
You can use the following python code:
num = input('Enter a number: ')
def checkArmstrong(num):
sum = 0
for i in str(num):
sum += (int(i) ** 3)
if sum == int(num):
return True
else:
return False
print(checkArmstrong(num))
Answered by
1
Question:-
Write a program to input a number and check whether it is an Armstrong number.
Program:-
This is written in Python.
n=int(input("Enter a number: "))
x, s=n, 0
while n!=0:
d=n%10
s=s+d**3
n=n//10
if(s==x):
print("Armstrong.")
else:
print("Not Armstrong.")
Similar questions