PHP Print Daffodil number function code

Source: Internet
Author: User
Tags php print
    1. PHP Narcissus number function--bbs.it-home.org
    2. function Winter ($num)
    3. {
    4. if ($num <1000) {
    5. Define Bits
    6. $ge = $num% 10;
    7. Define 10-bit
    8. $ten = (($num%100)-$ge)/10;
    9. Define the Hundred
    10. /*floor rounding, ignoring all numbers after the decimal point */
    11. $hundred =floor ($num/100);
    12. $sum 1= $ge * $ge * $ge + $ten * $ten * $ten + $hundred * $hundred * $hundred;
    13. if ($sum 1== $num) {
    14. return 1;
    15. } else{
    16. return 0;
    17. }

    18. } else{

    19. return-1;
    20. }
    21. }

    22. if (Winter (371) ==-1) {

    23. echo "number greater than 1000";
    24. }else{
    25. if (Winter (371)) {
    26. echo "Yes";
    27. } else{
    28. echo "No";
    29. }
    30. }
    31. ?>
Copy Code

Example 2,php to realize the number of daffodils

    1. for ($i =0; $i <1000; $i + +)
    2. {
    3. $a =floor ($i/100);//Find out the number of hundred
    4. =floor ($i/10)%10;//to find 10-digit number $b
    5. $c = $i%10;//to find the single digit
    6. if ($a * $a * $a + $b * $b * $b + $c * $c * $c = = $i)
    7. if (POW ($a, 3) +pow ($b, 3) +pow ($c, 3) = = $i)//Judgment hundred, 10 bits
    8. Bits of the cube and whether it equals this number itself
    9. {
    10. echo $i. "
      ";
    11. }
    12. }
    13. ?>
Copy Code
  • Related Article

    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.