Description:
Check if a number is an Armstrong number.
Check if a number is an Armstrong number.
C Code
#include <stdio.h>
#include <math.h>
int main() {
int n = 153, orig = 153, sum = 0;
while (n > 0) {
int r = n % 10;
sum += (int)pow(r, 3);
n /= 10;
}
printf("%d is Armstrong: %s\n", orig, (sum==orig)?"true":"false");
return 0;
}
Expected Output
153 is Armstrong: true