#include
#include
int main() {
int originalNum, num, lastDigit, digits, sum;
/* Input number from user */
printf("Enter any number to check Armstrong number: ");
scanf("%d", &num);
sum = 0;
originalNum = num;
/* Calculate the number of digits in the input number */
for (digits = 0; originalNum > 0; digits++) {
originalNum /= 10;
}
originalNum = num;
/* Compute the sum of the cubes of individual digits */
while (originalNum > 0) {
lastDigit = originalNum % 10;
sum += pow(lastDigit, digits);
originalNum /= 10;
}
/* Check if the sum equals the original number */
if (sum == num) {
printf("%d is an Armstrong number.\n", num);
} else {
printf("%d is not an Armstrong number.\n", num);
}
return 0;
}
0 comments:
Post a Comment
Thanks