Using the function output narcissistic number PTA

Refers to a number of N-bit daffodils positive integer (N≥3), on which digital bits of each of N power equals itself. For example: 153 = (1 ^ 3) + (5 ^ 3) + (3 ^ 3) this question requires the preparation of two functions, one determines whether the number of integer daffodils given, other printed out in ascending order given All daffodils interval number (m, n).

Function interface definition:

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

Narcissistic function determines whether the number is a number from daffodils, it returns 1, and 0 otherwise.
All functions PrintN daffodils interval number (m, n) within a print, each number per line. Topic guarantee 100≤m≤n≤10000.

Referee test program Example:

#include <stdio.h>

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;
}

/* 你的代码将被嵌在这里 */

Sample input:

153 400

Sample output:

153 is a narcissistic number
370
371

Code:

int narcissistic( int number )
{
	int i,n,sum=0,m=0,a=1,b;
	n=number;
	while(n)
	{
		n/=10;
		m++;
	}
	n=number;
	while(n)
	{
		a=1;
		b=n%10;
		for(i=1;i<=m;i++)a*=b;
		n/=10;
		sum+=a;
	}
	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)==1)
  printf("%d\n",i);
}

Here Insert Picture Description

Guess you like

Origin blog.csdn.net/qq_44256227/article/details/89743181