用 C语言编程:在窗体上以每行两个数的格式输出所有的“水仙花数”所谓“水仙花数”是指一个三位数.其各位数字的立方和等于该数本身
时间: 2023-10-27 08:46:03 浏览: 487
C语言案例-水仙花数.zip
Sure, the code to print all Armstrong numbers (also known as Narcissistic numbers) in C would be:
#include <stdio.h>
int main() {
int num, originalNum, remainder, result = 0;
for(num = 100; num <= 999; num++) {
originalNum = num;
while(originalNum != 0) {
remainder = originalNum % 10;
result += remainder * remainder * remainder;
originalNum /= 10;
}
if(result == num) {
printf("%d ", num);
}
result = 0;
}
return 0;
}
I hope this helps!
阅读全文