Question

An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 33 + 73 + 13 = 371.

Write a program to find all Armstrong number in the range of 0 and 999

Source Code

#include <stdio.h>

int main()
{
    int number, i, digit, sum;

    for (i = 0; i < 1000; i++)
    {
        number = i;
        sum = 0;
        
        while (number > 0)
        {
            digit = number % 10;
            sum += digit * digit * digit;
            number /= 10;
        }

        if (sum == i)
        {
            printf("%d\t", i);
        }
    }

    return 0;
}

Output

0 1 153 370 371 407