Easy PHP algorithm problem (with extensions)

Source: Internet
Author: User
Simple PHP algorithm problem (with extensions)

Simple PHP algorithm problem (to be perfected ...) )

Print only 0

The specific number is determined by the input parameter n

Print 00000 as N=5

Print n 0 based on n value

Print a line 0101010101010101010101

The specific number is determined by the input parameter n

such as test.php?n=3 printing 010

print 010101 based on n value ...

Implementation 1 00 111 0000 11111

For if implementation

 Php for($i= 0;$i< 10;$i++) {     for($j= 0;$j<=$i;$j++) {        if($i% 2 = = 0) {            Echo' 0 '; } Else {            Echo' 1 '; }    }    Echo'
';}?>

for&if Statement Implementation

For switch implementation

 Php for($i= 0;$i< 10;$i++) {     for($j= 0;$j<=$i;$j++) {        Switch($j% 2) {             Case' 0 ':Echo"0";  Break;  Case' 1 ':Echo"1";  Break; }    }    Echo'
';}?>

For&switch Statement Implementation

While if implementation

While switch implementation

 Php$i= 0; while($i< 10) {    $j= 0;  while($j<=$i) {        Switch($i% 2) {             Case0:Echo' 0 ';  Break;  Case1:Echo' 1 ';  Break; }        $j++; }    Echo'
'; $i++;}?>

While&switch Statement Implementation

Implementation 0 01 010 0101 ...

Implementation 0 01 012 0123 3210 210 10 0

Make a calculator.

such as Test.php?a=1&b=2&operator=jia output 3

such as Test.php?a=5&b=2&operator=jian output 3

such as Test.php?a=2&b=5&operator=cheng output 10

such as Test.php?a=6&b=3&operator=chu output 2

 Php$a=$_get[' A ']; $b=$_get[' B ']; $operator=$_get[' operator ']; functionCalculate$a,$b,$operator) {        Switch($operator) {             Case' Jia ':$result=$a+$b; return $result;  Break;  Case' Jian ':$result=$a-$b; return $result;  Break;  Case' Cheng ':$result=$a*$b; return $result;  Break;  Case' Chu ':$result=$a/$b; return $result;  Break; }    }    EchoCalculate$a,$b,$operator);?>

four-bit all-in-one computational function for subtraction processing

Advanced:

Number of daffodils

Bubble Sort Method

1/ F Corvoh
Hohojoho ... This is the most time-consuming, but the most interesting!
  • 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.