Armstrong Numbers
Sum each digit cubed, compare to the original
A number is an Armstrong number when the sum of its own digits, each raised to the power of the digit count, reconstructs the original number. For 153's three digits, that means summing each digit cubed and checking it lands back on 153.
Details
Animated on: n = 153 — check whether n equals the sum of its own digits, each raised to the digit-count's power.
Problem:Armstrong NumbersEasy
Sum each digit cubed, compare to the original
step 1 / 9
153 has 3 digits: 1, 5, 3. Check whether 1^3 + 5^3 + 3^3 equals 153.
1FUNCTION isArmstrong(n):2 digits = the digits of n3 sum = 04 FOR each digit d in digits:5 add d cubed to sum6 RETURN true if sum equals n, otherwise false
← / → step · space play · Home restart
Every step in words
Show all 9 steps
- 153 has 3 digits: 1, 5, 3. Check whether 1^3 + 5^3 + 3^3 equals 153.
- digit = 1.
- 1^3 = 1. running sum = 1.
- digit = 5.
- 5^3 = 125. running sum = 1 + 125 = 126.
- digit = 3.
- 3^3 = 27. running sum = 126 + 27 = 153.
- Sum of cubes = 153, with every digit now processed.
- 153 (sum of cubes) === 153 (original number) → true, 153 is an Armstrong number.
Now solve it yourself
Watching is the first half. The second is writing it without the animation.