题解 | #水仙花数#
水仙花数
https://www.nowcoder.com/practice/dc943274e8254a9eb074298fb2084703
#include <stdio.h> int main() { int a, b; while (scanf("%d %d", &a, &b) != EOF) { // 注意 while 处理多个 case // 64 位输出请用 printf("%lld") to int i=0;//遍历数字 int n=0;//代替i进行计算 int sum=0; int state=0;//记录状态,存在则为1,不存在则为0 for(i=a;i<=b;i++) { sum=0; n=i; while(n) { sum+=(n%10)*(n%10)*(n%10); n/=10; } if(sum==i) { printf("%d ",i); state=1; } } if(state==0) { printf("no\n"); } } return 0; }