C语言实现水仙花数算法
#include <stdio.h> #include <math.h>
int main() { int a, b, c;
for (a = 0; a <= 9; a++) {
for (b = 0; b <= 9; b++) {
for (c = 1; c <= 9; c++) {
int num = a * 100 + b * 10 + c;
int sum = pow(a, 3) + pow(b, 3) + pow(c, 3);
if (num == sum) {
printf('%d%d%d\n', a, b, c);
}
}
}
}
return 0;
}
原文地址: https://www.cveoy.top/t/topic/nnnV 著作权归作者所有。请勿转载和采集!