Experiment 4-2-5 narcissistic number (20 minutes)

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 = 131 ^ 31
. 3
+ 535 ^ 35
. 3
+ 333 ^ 33 is
. 3
. This problem requires programming, calculates the number of bits for all N daffodils.

Input format:
input line in a given positive integer N (3≤N≤7).

Output Format:
Output all N-bit daffodils ascending order, each number per line.

Sample input:
3

Output Sample:
153
370
371
407

 

. 1 #include <stdio.h>
 2 #include <math.h>
 . 3  
. 4  // determines whether the number of daffodils, if the output. 1 
. 5  int narcissistic ( int Number) {
 . 6      int X = Number, Number = Y, n-= 0 , SUM = 0 ;
 . 7      the while (X> 0 ) {
 . 8          n-++ ;
 . 9          X / = 10 ;
 10      }
 . 11      the while (Y> 0 ) {
 12 is          SUM + = POW (Y% 10 , n-);
 13 is          Y / =10 ;
 14      }
 15      IF (SUM == Number) {
 16          return  . 1 ;
 . 17      }
 18 is      the else {
 . 19          return  0 ;
 20 is      }
 21 is  }
 22 is  
23 is  // Output [m, daffodils the number n) in the range of 
24  void PrintN ( int m, int n-) {
 25      for ( int I = m; I <n-; I ++ ) {
 26 is          IF (narcissistic (I)) {
 27              the printf ( " % D \ n-", i);
28         }
29     }
30 }
31 
32 int main(){
33     int n;
34     scanf("%d", &n);
35     PrintN (pow(10,n-1), pow(10,n));
36     return 0;
37 }

Guess you like

Origin www.cnblogs.com/xiaolitongxueyaoshangjin/p/12105213.html