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
++=153
Another name for an Armstrong number is a narcissistic number.
Algorithm
-
Variable
nstores 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
nis greater than 0. Oncenis 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 = 0tem = nwhile tem > 0:digit = tem % 10sum += digit ** 3tem //= 10if n == sum:print(n,"Yes, it is an Armstrong number")else:print(n,"No, it isn't an Armstrong number")
Enter the input below