How to Use php for multiplication, how to buy a chicken for a hundred dollars, and how to bridge the bridge
Exercise Question 1: crossing the bridge
Suppose someone has 100,000 in cash.
Each time you pass through an intersection, you need to pay a fee.
The payment rule is that when his cash is greater than 50,000, he must pay 5% each time. If his cash is less than or equal to 50,000, he must pay 5,000 each time.
Please write a program to calculate how many times this person can pass through this intersection.
for ($i=100000,$num = 0; $i >= 5000; ) { if ($i >= 50000) { $i = 0.95*$i; }else{ $i = $i -5000; } $num = $num + 1;}echo $num,'<br />';
Exercise Question 2: Multiplication
for ($i=1; $i <= 9 ; $i++) { for($j=1; $j<=$i; $j++) { echo $j,'*',$i ,'=' , $j*$i , ' '; } echo '<br />';}
Exercise 3: buy a chicken for a hundred dollars
Course 22 Zhang qiujian computing Sutra was written in the 5th century. The author is from Northern Wei.
The last question in the book is a bright spot. It is also known as the question of "buy a chicken for a hundred dollars,
The original texts in the famous saying that the county magistrate asked the prodigy are as follows:
Today there is a rooster, worth five; a rooster, worth three; a rooster, worth one;
I want to buy more than one chicken for a hundred dollars. What are the geometric aspects of the rooster, the mother, and the chicks?
The question is: the rooster has five yuan, the hen has three yuan, and the chicken has three yuan,
Now I have bought 100 chickens for 100 RMB,
Q: How many of the 100 chickens are rooster, hen, and chicken? (Set at least one for each type)
for ($i=1; $i <100 ; $i++) { for ($j=1; $j < 100; $j++) { for ($k=1; $k <100 ; $k++) { if ( ($i+$j+$k == 100)&&($i*5+$j*3+$k/3 == 100) ) { echo $i,'<br />',$j,'<br />',$k,'<br />'; } } }}