Summary of methods to implement the ninety-nine multiplication table of PHP classic basic test questions

伊谢尔伦
Release: 2023-03-10 22:34:02
Original
1978 people have browsed it

For those new to PHP, writing theNine-Nine Multiplication Tablein PHP is undoubtedly a very classicpracticequestion. It is quite a test of logic.

The so-called difficult thing is not difficult for those who know it, but it is not difficult for those who know it. For some veterans, this is really nothing. But for novices, it can train logical thinking.

If there are no restrictions, you may be able to type the entire code in two minutes. If you are proficient, you can also implement it in several ways. But what if you are asked to write the multiplication table for four angles? (It can continue to be extended)

The following will introduce several methods to implement the nine-nine multiplication table of PHP classic basic test questions:

1. Usefor loopto print nine Multiplication table:

"; }
Copy after login

2. Usewhile loopto print the multiplication table

"; $j++; }
Copy after login

3. Use do while loop to print the multiplication table

"; $j++; } while($j<=9);
Copy after login

Use a for loop to output the ninety-nine multiplication table in the form oftable

Angle one: (the most common conventional writing method)

"; for($j=1;$j<=9;$j++){ echo ""; for($i=1;$i<=$j;$i++){ echo "{$i}*{$j}=".($i*$j).""; } echo ""; } echo "";
Copy after login

Angle two: (common to the conventional writing method X-axis symmetry)

"; for($j=9;$j>=1;$j--){ echo ""; for($i=1;$i<=$j;$i++){ echo "{$i}*{$j}=".($i*$j).""; } echo ""; } echo "";
Copy after login

Angle three: (Y-axis symmetry with angle two)

"; for($j=9;$j>=1;$j--){ echo ""; for($z=0;$z<9-$j;$z++){ echo " "; } for($i=1;$i<=$j;$i++){ echo "{$i}*{$j}=".($i*$j).""; } echo ""; } echo "";
Copy after login

Angle four: (Y-axis symmetry with conventional writing)

"; for($j=1;$j<=9;$j++){ echo ""; for($z=0;$z<9-$j;$z++){ echo " "; } for($i=$j;$i>=1;$i--){ echo "{$i}*{$j}=".($i*$j).""; } echo ""; } echo "";
Copy after login

The above is the detailed content of Summary of methods to implement the ninety-nine multiplication table of PHP classic basic test questions. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!