题解 | #水仙花数#
水仙花数
https://www.nowcoder.com/practice/dc943274e8254a9eb074298fb2084703
#include <stdio.h> int main() { int a, b; while (scanf("%d %d", &a, &b) != EOF) { // 注意 while 处理多个 case int count = 0; for (int i = a; i <= b; i++) { int tmp = i; int sum = 0; while (tmp != 0) { //a==0说明上一个循环的a已经是个位数了 int yuShu = tmp % 10; sum = sum + yuShu * yuShu * yuShu; tmp = tmp / 10;//把商赋值给a,再循环 } if(sum == i) { printf("%d ", sum); count++; } } if(count == 0) printf("no"); printf("\n");//最后换行,这个可能是有输出水仙花数,也可能是输出no之后的换行 } return 0; }