Example of php implementation of daffodils. 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. Copy the code as follows :? 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 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 ();
Bytes. In fact, only the three-digit self-power is the number of daffodils. 4, 5, 6, and so on. The code is as follows :?...