Kodewick
Start learning →
Starter←→0 / 50

Armstrong numbers

#015Startera*a*a + b*b*b + c*c*c6 min

An Armstrong number (narcissistic number) here is a 3-digit number where the cubes of its three digits add up to the number itself. For example, 153 = 1³ + 5³ + 3³. Show all of them from smallest to largest, one per line. In the starter, a, b, c are the hundreds, tens and ones digits.

Should show
153
370
371
407
main.c
#include <stdio.h>

int main(void) {
    for (int n = 100; n <= 999; n++) {
        int a = n / 100;
        int b = n / 10 % 10;
        int c = n % 10;
        // your code here: if the sum of the three cubes equals n, show n
    }
    return 0;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.