C Narcissus Number Program
水仙花数,也叫做自恋数,是指一个三位数,其各位数字的立方和等于该数本身。
Below is the program written in C language for finding Armstrong numbers.
#include <stdio.h>
int main() {
int num, originalNum, remainder, result = 0;
printf("请输入一个三位数: ");
scanf("%d", &num);
originalNum = num;
while (originalNum != 0) {
remainder = originalNum % 10;
result += remainder * remainder * remainder;
originalNum /= 10;
}
if (result == num) {
printf("%d 是水仙花数\n", num);
} else {
printf("%d 不是水仙花数\n", num);
}
return 0;
}
After running the program, the user will be prompted to enter a three-digit number, and then the program will determine whether the number is an Armstrong number and display the result.