phpWhat is the number of daffodils?
The so-called "daffodil number" refers to an n-digit number (n≥3), the sum of the nth power of the numbers in each digit is equal to itself.
PHP program for finding the number of daffodils, there are many ways to write it:
Method Example 1:
1000以内的水仙花数: '; for ( $i = 100; $i < 1000; ++ $i ) { $hundreds = floor( $i / 100); //分解出百位 $tens = floor( $i / 10 ) % 10; //分解出十位 $ones = floor( $i % 10 ); //分解出个位 if (bcpow($hundreds,'3')+bcpow($tens,'3')+bcpow($ones,'3') == $i) echo $i.""; } ?>
Output:
1000以内的水仙花数: 153 370 371 407
Method example two:
"; } } } }
Output:
153 370 371 407
Method example three:
Copy after login
Method example four :
' : ''; } } 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; } } Armstrong::index();
Output:
153 370 371 407 1634 8208 9474 54748 92727 93084
Method example five:
Output:
Yes
Related recommendations: "PHP Tutorial》
The above is the detailed content of What is the daffodil number in php. For more information, please follow other related articles on the PHP Chinese website!