水仙花数,四叶玫瑰数,五角星数,六合数,北斗七星数,八仙数,九九重阳数,十全十美数

#include 
int narcissistic( int number );
void PrintN( int m, int n );

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;
}
int narcissistic( int number )
{
	int n = 0;
	int k = number;
	int l = number;
	int flag = 0;
	int sum = 0;
	while(k > 0)   
	{
		k /= 10;
		n++;
	}
	int x;
	int j;
	while(l > 0) 
	{
		x = l%10;
		for (j = 0; j < n-1; j++)
		{
			x=x*(l%10);
		}
		sum += x;
		l/=10;
	}
	if (sum  == number)flag = 1;
	
	return flag;
}
void PrintN( int m, int n )
{
	for (; m<= n; m++)
	{
		if(narcissistic( m ))
		{
			printf("%d\n",m );
		}
	}
}

计算机性能差,五分钟跑了这么多…水仙花数,四叶玫瑰数,五角星数,六合数,北斗七星数,八仙数,九九重阳数,十全十美数_第1张图片

你可能感兴趣的:(c语言,编程学习)