Learner Level

Implement the isArmstrongNumber method that checks whether a number is equal to the sum of its digits raised to the digit count.

The input contains an integer n. Your task is to check whether n is an Armstrong number.

An Armstrong number is equal to the sum of its digits raised to the power of the number of digits. For example, 153 has three digits, and 1^3 + 5^3 + 3^3 = 153, so it is an Armstrong number.

Example 1
Input:
n (int) = 153
Return:
(boolean) true
Example 2
Input:
n (int) = 9474
Return:
(boolean) true
Example 3
Input:
n (int) = 123
Return:
(boolean) false

First count how many digits are present in the number.

Then process each digit, raise it to the power of the digit count, and add it to a running sum. At the end, compare the sum with the original number. If both are equal, return true; otherwise return false.

Pseudocode:

function isArmstrongNumber(n):
    original = n
    digits = count digits in n
    sum = 0
    while n > 0:
        digit = n % 10
        sum = sum + power(digit, digits)
        n = n / 10
    return sum == original
Run your code to see the result.