Php prints the daffodils function code

Source: Internet
Author: User
Php prints the daffodils function code

  1. Php daffodils function --bbs.it-home.org
  2. Function winter ($ num)
  3. {
  4. If ($ num <1000 ){
  5. // Define a single bit
  6. $ Ge = $ num % 10;
  7. // Define ten
  8. $ Ten = ($ num % 100)-$ ge)/10;
  9. // Defines the hundred bits
  10. /* Floor rounded up, ignoring all numbers after the decimal point */
  11. $ Hundred = floor ($ num/100 );
  12. $ Sum1 = $ ge * $ ge + $ ten * $ ten + $ hundred * $ hundred;
  13. If ($ sum1 = $ 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. ?>

Example 2: php implements daffodils

  1. For ($ I = 0; I I <1000; $ I ++)
  2. {
  3. $ A = floor ($ I/100); // obtain hundreds of digits
  4. $ B = floor ($ I/10) % 10; // Obtain ten digits
  5. $ C = $ I % 10; // Obtain the single digit
  6. // If ($ a * $ a + $ B * $ B + $ c * $ c = $ I)
  7. If (pow ($ a, 3) + pow ($ B, 3) + pow ($ c, 3) = $ I) // judge hundreds or ten digits
  8. Is the cube of a single digit equal to the number itself?
  9. {
  10. Echo $ I ."
    ";
  11. }
  12. }
  13. ?>

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.