题解 | #水仙花数#
水仙花数
https://www.nowcoder.com/practice/dc943274e8254a9eb074298fb2084703
#include <stdio.h>
int main()
{
int m, n;
int i, j;
int temp;
int sum = 0;
int count = 0;
while (scanf("%d %d", &m, &n) != EOF)
{
for (i = m; i <= n; i++)
{
temp = 0;
sum = 0;
for (j = 10; j <= i * 10; j *= 10)
{
if (i % j <= i)
{
temp = (i % j - temp) / (j / 10);
sum = sum + temp * temp * temp;
}
}
if (sum == i)
{
printf("%d ", i);
count++;
}
}
if (count == 0)
{
printf("no\n");
}
else
{
printf("\n");
}
}
return 0;
}
#题解#
查看11道真题和解析