7

Note:

Let number = abcd and total digits = n.

If aⁿ + bⁿ + cⁿ + dⁿ = original number, then it is an Armstrong number.

Example 1: 153 → 1³ + 5³ + 3³ = 1 + 125 + 27 = 153

Example 2: 1634 → 1⁴ + 6⁴ + 3⁴ + 4⁴ = 1 + 1296 + 81 + 256 = 1634

Solution 1: Manual power (safe, no double) C++ 19 lines
int main() {
    int n = 1634;
    int len = to_string(n).length();
    int temp = n;
    int sum = 0;

    while(temp != 0){
        int digit = temp % 10;
        int power = 1;
        for(int i = 0; i < len; i++){
            power = power * digit;
        }
        sum = sum + power;
        temp = temp / 10;
    }

    if(sum == n) cout << "Armstrong";
    else cout << "Not Armstrong";
}
Solution 2: Using pow() (round is needed) C++ 2 lines
int digit = temp % 10;
sum += (int)round(pow(digit, len));

Note: pow() returns a double, so a direct int cast can give a wrong answer (for example 124.99999 becomes 124). Use round() to be safe.