void PrintN(int m, int n)
{
if (m == n) {}
else {
for (int i = m + 1; i < n; i++)
{
if (narcissistic(i)) printf("%d\n", i);
}
}
}
int narcissistic(int number)
{
int sum = 0, num = number, cnt = 0;
while(number)
{
cnt=cnt+1;
number=number/10;
}
number=num;
while(number)
{
sum=pow(number%10,cnt) + sum;
number=number/10;
}
if (sum == num) {
return 1;
}
return 0;
}
PTA:6-11 使用函数输出水仙花数
最新推荐文章于 2024-10-07 09:17:55 发布