Related Tags

python3
armstrong
communitycreator

# How to find if a given number is an Armstrong number

An Armstrong number is defined as the sum of cubes of individual digits of a given number that result in the same number.

## Example

$1^{3}$+$5^{3}$+$3^{3}$=153

Another name for an Armstrong number is a narcissistic number.

## Algorithm

• Variable n stores the input value by the user.

• The individual digits are acquired by performing n mod 10.

• It cubes the given number individually.

• Then, the number is divided by 10 to obtain the second numerical.

• The loop is given until the value of n is greater than 0. Once n is less than 0, end the while loop.

• If the given number is equal to the sum of individual cubes, then it will show that the number is an Armstrong number.

## Code

n = int(input("Enter a number: "))
sum = 0
tem = n

while tem > 0:
digit = tem % 10
sum += digit ** 3
tem //= 10

if n == sum:
print(n,"Yes, it is an  Armstrong number")
else:
print(n,"No, it isn't an Armstrong number")



Enter the input below

RELATED TAGS

python3
armstrong
communitycreator

CONTRIBUTOR