题解 | #变种水仙花#
变种水仙花
https://www.nowcoder.com/practice/c178e3f5cc4641dfbc8b020ae79e2b71
#include <stdio.h> #include <math.h> int IsLilyNumber(int num) { int flag = 0; int sum = 0; for(int i = 1; num / (int)pow(10, i) > 0; i++) { sum += (num % (int)pow(10, i)) * (num / (int)pow(10, i)); } if(sum == num) { flag = 1; } return flag; } int main() { for(int i = 10000; i < 100000; i++) { if(IsLilyNumber(i)) { printf("%d ", i); } } }