This article mainly introduces the example of using php to implement daffodils. For more information, see
This article mainly introduces the example of using php to implement daffodils. For more information, see
Self-power, also known as the number of Armstrong, is commonly referred to as the number of daffodils. In fact, only the three-digit self-power is the number of daffodils. 4, 5, 6, and so on.
The Code is as follows:
// Armstrong number: a k-digit number. The sum of the k-power of the number on each digit is equal to itself. (For example, 1 ^ 3 + 5 ^ 3 + 3 ^ 3 = 153)
Class Armstrong {
Static function index (){
For ($ I = 100; $ I <100000; $ I ++ ){
Echo self: is_armstrong ($ I )? $ I .'
':'';
}
}
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 ();