题解 | #水仙花数#
水仙花数
https://www.nowcoder.com/practice/dc943274e8254a9eb074298fb2084703
#include<stdio.h>
int main() {
int m, n, i, a, b, c, flag = 0;
while (scanf("%d %d", &m, &n) != EOF) {
for (i = m; i <= n; i++) {
a = i % 10;
b = (i / 10) % 10;
c = i / 100;
while ((pow(a, 3) + pow(b, 3) + pow(c, 3)) == i) {
flag += 1;
printf("%d ", i);
break;
}
}
if (flag == 0) {
printf("no\n");
}
}
}
int main() {
int m, n, i, a, b, c, flag = 0;
while (scanf("%d %d", &m, &n) != EOF) {
for (i = m; i <= n; i++) {
a = i % 10;
b = (i / 10) % 10;
c = i / 100;
while ((pow(a, 3) + pow(b, 3) + pow(c, 3)) == i) {
flag += 1;
printf("%d ", i);
break;
}
}
if (flag == 0) {
printf("no\n");
}
}
}