水仙花数是指一个 3 位数,它的每个位上的数字的 3次幂之和等于它本身(例如:\(1^3\) + \(5^3\)+ \(3^3\) = 153)。 请编写程序,在一行内,按从小到大的顺序输出所有水仙花数,以空格作为分割
int main() { int i; for(i = 100; i <= 999; i++) { int a = i / 100; int b = i / 10 % 10; int c = i % 10;
if(a*a*a + b*b*b + c*c*c == i) { printf("%d ", i); } } return 0;
}
评论
include <stdio.h>
int main() { int i; for(i = 100; i <= 999; i++) { int a = i / 100;
int b = i / 10 % 10;
int c = i % 10;
}