题解 | #水仙花数#
水仙花数
https://www.nowcoder.com/practice/dc943274e8254a9eb074298fb2084703
#include <stdio.h> #include<math.h> int pdss(int x) { int start = x; int num = 0; int tmp = 0; while (x) { tmp = x % 10; num += pow(tmp, 3); x = x / 10; } if (num == start) return 1; return 0; } void print(int x,int y) { int i=0;int flag=1; for(i=x;i<=y;i++) { if(pdss(i)) { flag=0; printf("%d ",i); } } if(flag==1) { printf("no"); } printf("\n"); } int main() { int a, b; while (scanf("%d %d", &a, &b) != EOF) { // 注意 while 处理多个 case print(a,b); } return 0; }