The
Narcissus number refers to an n-digit (n≥3), in which the sum of the n powers of the number on each bit is equal to itself. (For example: 1^3 + 3^3+ 5^3 = 153) This article mainly introduces the realization of the number of daffodils in PHP 4 examples to share, the need for friends can refer to the next
Example 1: Code as follows: <?php for ($q =1 $q <=9; $q + +) { for ($w =0; $w <=9; $w + +) { for ($e =0 $e <=9; $e + +) { if ($q * $q * $q + $w * $w * $w + $e * $e * $e = 100* $q + 10* $w + $e) { echo "$q $w $e". <p> "; } { }?> Example 2: Code as follows: <?php func tion Cube ($n) { return $n * $n * $n;} function is_narcissistic ($n) { $hundreds = Floor ($n/100); //decomposition of the hundred $tens = Floor ($n/10)% 10; //10-bit $ones = floor ($n% 10); //decomposition of single-digit return (BOOL) (Cube ($hundreds) +cube ($tens) +cube ($ones) = = $n); } for ($i = $i < 1000 + + $i) { if (is_narcissistic ($i)) &NBS P echo $i. " n "; }?> Example 3: The code is as follows: <?php//Armstrong number: A K-digit, the sum of the K-power of the number on each bit of it is equal to itself. (For example: 1^3 + 5^3 + 3^3 = 153) class Armstrong { static function index () { for ($i = $i < 100000; $i + +) { echo self::is_armstrong ($i)? $i. ' <br> ': '; }   static function Is_armstrong ($num) { $s = 0; $k = strlen ($num); $d = Str_split ( $num); foreach ($d as $r) { $s + = Bcpow ($r, $k); } return $num = = $s; &NBSP}} armstrong::index (); Example 4: Code as follows: <html> <head> <title></title> </head> & lt;body> <?php function Winter ($num) { if ($num <1000) {  ; //definition single-digit $ge = $num% 10; //definition 10-bit $ten = (($num%100)-$ge)/10; //defines the hundred /*floor rounding, ignoring all numbers after the decimal point/ &NBSP $hundred =floor ($num/100); $sum 1= $ge * $ge * $ge + $ten * $ten * $ten + $hundred * $hundred * $hundred; if ($sum 1== $num) { return 1; else{ & nbsp return 0; & nbsp else{ return-1; &NBSP nbsp if (Winter (371) ==-1) { echo "A number greater than 1000"; }else{ if (Winter (371)) { &NBSP ; echo "Yes"; } els e{ echo "No"  } } ?> </body> </html>