进入学习php语言状态。昨日看了一天视频。才能够把这个小口诀表实现。好难啊。
里面有个口诀表的函数、
<?php echo "=============================================<br/>"; for ($a=1;$a<=9;$a++){ //循环输出a a默认值是1 a的值不会大于9 且不断加一 for ($b=1;$b<=$a;$b++){//{b默认值是1 且b值不能大于a值 也就是九 加一运算 /*一开始a等于1的,满足$a<=9 往下运行,b=1,满足$b<=$a,输出echo "$b x $a = $c" ; 当b加一运算后,,不能满足$b<=$a,跳出循环,运行echo "<br/>" 回到$a 循环,a加一 运算 此时a=2 满足$a<=9 。往下运行,b=1,满足$b<=$a,输出echo "$b x $a = $c",输出后 b加一运算了 等于2还是满足$b<=$a ,继续往下运行,b=2,满足$b<=$a,输出echo "$b x $a = $c" */ $c=$a*$b; //定义变量C的值 echo "$b x $a = $c" ; //输出变量b x 变量a 等于变量c echo " "; //空格 } echo "<br/>"; //回车 } /*以上几句代码实现99乘法表 1 x 1 = 1 1 x 2 = 2 2 x 2 = 4 1 x 3 = 3 2 x 3 = 6 3 x 3 = 9 1 x 4 = 4 2 x 4 = 8 3 x 4 = 12 4 x 4 = 16 1 x 5 = 5 2 x 5 = 10 3 x 5 = 15 4 x 5 = 20 5 x 5 = 25 1 x 6 = 6 2 x 6 = 12 3 x 6 = 18 4 x 6 = 24 5 x 6 = 30 6 x 6 = 36 1 x 7 = 7 2 x 7 = 14 3 x 7 = 21 4 x 7 = 28 5 x 7 = 35 6 x 7 = 42 7 x 7 = 49 1 x 8 = 8 2 x 8 = 16 3 x 8 = 24 4 x 8 = 32 5 x 8 = 40 6 x 8 = 48 7 x 8 = 56 8 x 8 = 64 1 x 9 = 9 2 x 9 = 18 3 x 9 = 27 4 x 9 = 36 5 x 9 = 45 6 x 9 = 54 7 x 9 = 63 8 x 9 = 72 9 x 9 = 81 */ ?> <?php echo "=============================================<br/>"; for ($x=9;$x>=1;$x-- ){ for ($y=9;$y>=$x;$y--){ $z=$x*$y; echo "$y X $x =$z"; echo " "; } echo "<br/>"; } ?> <?php //******乘法表函数********* echo "=============================================<br/>"; function cheng($a,$b=9){ //a是一个乘数;b是另一个乘数,初始值是9 for ($x=$a;$x<=$b;$x++){ for ($y=1;$y<=$x;$y++){ $z=$y*$x; echo "$y X $x =$z"; echo " "; } echo "<br/>"; } } echo cheng(3,7); 调用了函数 echo "=============================================<br/>"; echo cheng(1 ); //**********乘法表函数********* ?>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。