PHP Exercises (ii)

Source: Internet
Author: User
PHP Exercises (II.)

Program 6.
title: Suppose someone has 100,000 of cash, every intersection need to pay the rules for the payment when he is more than 50,000 per cent of the amount of cash to be 5, if the cash is less than or equal to 50,000 per 5,000. Ask how many times this person can pass 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++;Ten } One Echo' Can pass '.$i. ' Second intersection
';

Program 7.
Title: Printing 99 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.
title: Hundred Money Hundred Chicken, Rooster 5 text Money One, hen 3 text money A only, chicken 1 text Money three only, with 100 money buys 100, ask, rooster, hen, chicken each a few?

1 $x 1= 0;//Number of Cocks2 $x 2= 0;//Number of Hens3 $x 3= 0;//Number of chickens4  for($x 1= 1;$x 1<= 20;$x 1++) {5      for($x 2= 1;$x 2<= (33-$x 1);$x 2++) {6         $x 3= 100-$x 1-$x 2;7         if(100 = = ($x 1+$x 2+$x 3/3) ) {8             Echo' Number of cocks: '.$x 1. ' Number of hens: '.$x 2. ' Number of chicks '.$x 3. '
';9 }Ten } One}

Program 9.
Title: Number of primes within 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) {Ten                  Break; One             } A         } -     } -     $num++; the}

  • 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.