您好,登錄后才能下訂單哦!
進入學習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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。