PHP经典实例教程(九九乘法表)

 1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 2 <HTML>
 3 <HEAD>
 4 <TITLE> New Document </TITLE>
 5 <META NAME="Generator" CONTENT="EditPlus">
 6 <META NAME="Author" CONTENT="">
 7 <META NAME="Keywords" CONTENT="">
 8 <META NAME="Description" CONTENT="">
 9 </HEAD>
10 
11 <BODY>
12 <?php
13     echo "<p>第一种</p>";
14     echo "<table width='600' border='1' cellspacing='0' cellspadding='0' >";
15     for($j=1;$j<=9;$j++){
16         echo "<tr>";
17         for($i=1;$i<=$j;$i++){
18             echo "<td>{$i}*{$j}=".($i*$j)."</td>";
19         }
20         echo "</tr>";
21     }
22     echo "</table>";
23 
24     echo "<p>第二种</p>";
25 
26 
27     echo "<table width='600' border='1' cellspacing='0' cellspadding='0' >";
28     for($j=9;$j>=1;$j--){
29         echo "<tr>";
30         for($i=1;$i<=$j;$i++){
31             echo "<td>{$i}*{$j}=".($i*$j)."</td>";
32         }
33         echo "</tr>";
34     }
35     echo "</table>";
36 
37 
38     echo "<p>第三种</p>";
39 
40 
41     echo "<table width='600' border='1' cellspacing='0' cellspadding='0' >";
42     for($j=9;$j>=1;$j--){
43         echo "<tr>";
44         for($z=0;$z<9-$j;$z++){
45             echo "<td>&nbsp;</td>";
46         }
47         for($i=1;$i<=$j;$i++){
48             echo "<td>{$i}*{$j}=".($i*$j)."</td>";
49         }
50         echo "</tr>";
51     }
52     echo "</table>";
53 
54 
55 
56     echo "<p>第四种</p>";
57 
58 
59     echo "<table width='600' border='1' cellspacing='0' cellspadding='0' >";
60     for($j=1;$j<=9;$j++){
61         echo "<tr>";
62         
63         for($p=0;$p<9-$j;$p++){
64             echo "<td>&nbsp;</td>";
65         }
66 
67         for($i=$j;$i>=1;$i--){
68             echo "<td>{$i}*{$j}=".($i*$j)."</td>";
69         }
70         echo "</tr>";
71     }
72     echo "</table>";
73 
74 
75     echo "<p></p>";
76 ?>
77 </BODY>
78 </HTML>
one

 界面分别是:

里面的规律是:看九九乘法表的走势,去定最外层的for循环,看列的变化:从1到9,还是9到1

posted on 2013-06-06 15:31  福气满满好运连连  阅读(501)  评论(0编辑  收藏  举报