Php implementation of daffodils code sharing

Source: Internet
Author: User
Php implementation of daffodils code sharing

The so-called Number of daffodils, that is, the number of self-power, also known as the number of Armstrong, commonly known as the number of daffodils. In fact, only the three-digit self-power is the number of daffodils. 4, 5, 6, and so on.

For example, php implements the daffodils code.

  1. // 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)
  2. Class Armstrong {
  3. Static function index (){
  4. For ($ I = 100; $ I <100000; $ I ++ ){
  5. Echo self: is_armstrong ($ I )? $ I .'
    ':'';
  6. }
  7. } // Edit by bbs.it-home.org
  8. Static function is_armstrong ($ num ){
  9. $ S = 0;
  10. $ K = strlen ($ num );
  11. $ D = str_split ($ num );
  12. Foreach ($ d as $ r ){
  13. $ S + = bcpow ($ r, $ k );
  14. }
  15. Return $ num = $ s;
  16. }
  17. }
  18. Armstrong: index ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.