PHP exercise question (2), php exercise question _ PHP Tutorial

Source: Internet
Author: User
PHP exercises (2): php exercises. PHP exercise (2), php exercise program 6. question: If a person has 100,000 yuan in cash and needs to pay a fee every time he passes through an intersection, the rule is that when his cash is greater than 50,000, he needs PHP exercises every time (2). php exercises

Program 6.
Question:Assume that a person has 100,000 yuan in cash and must pay 50,000 yuan each time after the intersection. if the cash is less than or equal to 50,000, 5,000 yuan is required each time. ask how many times this person can pass through this intersection.

1 $ money = 100000; 2 $ I = 0; 3 while ($ money >=5000) {4 if ($ money> 50000) {5 $ money * = 95/100; 6} else if ($ money <= 50000) {7 $ money-= 5000; 8} 9 $ I ++; 10} 11 echo 'can pass '. $ I. 'intersection
';

Program 7.
Question:Print the 9-9 Multiplication table

1 for($i = 1; $i < 10; $i++) {2     for($j = 1; $j <= $i; $j++) {3         echo $j . 'x' . $i . '=' . $i*$j . '  ';4     }5     echo '
';6 }

Program 8.
Question:100 RMB for a rooster, 5 RMB for a rooster, 3 RMB for a hen, 3 RMB for a chicken, 3 RMB for a rooster, and 100 RMB for a rooster, how many chicks?

1 $ x1 = 0; // Number of Cocks 2 $ x2 = 0; // number of hens 3 $ x3 = 0; // number of chicks 4 for ($ x1 = 1; $ x1 <= 20; $ x1 ++) {5 for ($ x2 = 1; $ x2 <= (33-$ x1); $ x2 ++) {6 $ x3 = 100-$ x1-$ x2; 7 if (100 = ($ x1 * 5 + $ x2 * 3 + $ x3/3 )) {8 echo 'Rooster count :'. $ x1. 'The number of hens is :'. $ x2. 'number of chicks is '. $ x3.'
'; 9} 10} 11}

Program 9.
Question:Evaluate the prime number from 1 to 100

 1 $num = 2; 2 while($num <= 100) { 3     if( $num <= 3) { 4         echo $num . '  '; 5     } else { 6         for( $j = 2; $j <= $num; $j++) { 7             if( $j == $num ) { 8                 echo $num . '  '; 9             } else if( $num%$j == 0) {10                 break;11             }12         }13     }14     $num++;15 }

Exercise (2), php exercise program 6. question: Suppose a person has 100,000 in cash and needs to pay a fee every time he passes through an intersection. The rule is that when his cash exceeds 50,000, he needs to pay a fee every time...

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.