题解 | #变种水仙花#
变种水仙花
https://www.nowcoder.com/practice/c178e3f5cc4641dfbc8b020ae79e2b71
#include<stdio.h>
#include <math.h>
int main()
{
int LilyNumber[100] = { 0 };
int i = 0;
for (int n = 10000; n <= 99999; n++)
{
int sum = 0;
int num = 0;
int x = n;
while (x)
{
x /= 10;
num++;
}
while (num--)
{
int a = n / pow(10, num);
int b = n % (int)pow(10, num);
int c = a * b;
sum += c;
}
if (sum == n)
{
LilyNumber[i++] = sum;
}
}
for (int j = 0; j < i; j++)
{
printf("%d ", LilyNumber[j]);
}
return 0;
}
查看25道真题和解析