PHP exercises (2) and 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 <br/> ';
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 '<br/>';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. '<br/>'; 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 }