Check Whether a Number is an Armstrong Number
#include <stdio.h>
int main() {
int number, originalNumber, remainder;
int result = 0;
printf("Enter an integer: ");
scanf("%d", &number);
originalNumber = number; // Save the original number
// Iterate over each digit
while (number != 0) {
remainder = number % 10; // Get last digit
result += remainder * remainder * remainder; // Sum the cubes of digits
number /= 10; // Remove last digit
}
if (result == originalNumber)
printf("%d is an Armstrong number.\n", originalNumber);
else
printf("%d is not an Armstrong number.\n", originalNumber);
return 0;
}
Enter an integer: 153
153 is an Armstrong number.
An Armstrong (or narcissistic) number is equal to the sum of the cubes of its digits. This program extracts each digit from the rightmost side, cubes it, adds it to a running total, and finally checks if the sum matches the original number. The classic three‑digit Armstrong numbers are 153, 370, 371 and 407.
