How to Use php for multiplication, how to buy a chicken for a hundred dollars, and how to bridge the bridge

Source: Internet
Author: User

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 , '&nbsp;';    }    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 />';            }        }    }}

 

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.