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