#include <stdio.h>
#include <math.h>
int narcissistic( int number )
{
int l,n,i = 0,k,sum = 0,m;
n = number;
while(n)
{
n = n/10;
i++;
}
n = number;
for(k = 0;k < i;k++)
{
m = n%10;
n = n/10;
int pow = 1;
for(l = 0;l < i;l++)
{
pow=m*pow;
}
sum = sum + pow;
}
if (sum == number)
return 1;
else
return 0;
}
void PrintN( int m, int n )
{
int i;
for(i = m+1;i < n;i++)
{
if(narcissistic(i))
printf("%d\n",i);
}
}
int main()
{
int m, n;
scanf("%d %d", &m, &n);
if ( narcissistic(m) )
printf("%d is a narcissistic number\n", m);
PrintN(m, n);
if ( narcissistic(n) )
printf("%d is a narcissistic number\n", n);
return 0;
}
水仙花数是指一个N位正整数(N≥3),它的每个位上的数字的N次幂之和等于它本身。例如:153=1 3 +5 3 +3 3 。 本题要求编写两个函数,一个判断给定整数是否水仙花数,另一个按从
最新推荐文章于 2022-03-08 11:56:45 发布