<u>复制代码</u> 代码如下: <br><?php <BR>//杨辉三角 <br>for ($i=6;$i >= 0;$i--) <br>{ <br>for ($j=$i;$j { <br>if ($j { <br>echo "<b>a</b>"; <br>}else <br>{ <br>echo "<br>"; <br>} <br>} <br>} <br>?> <br> <br>PHP打印杨辉三角自定义 <br><u>复制代码</u> 代码如下: <br><form method="post" action="<?php%20echo(%24PHP_SELF);%20?>"> <br>输入杨辉三角的阶数:<input type="text" name="givenlines" size="5"> <br><input type="submit" name="submit" value="打印杨辉三角形"> <br> </form> <br><?php <BR>function yanghui($line) <br>{ <br>echo "<table>"; <br>for($i=1;$i{ <br>echo "<tr>"; <br>for($j=1;$j{ <br>$yh[$i][1]=1; <br>if ($i==$j) $yh[$i][$j]=1; <br>else $yh[$i][$j]=$yh[$i-1][$j-1]+$yh[$i-1][$j]; <br>echo "<td width="40"> <font color="#0000FF">"; <br>echo $yh[$i][$j]; <br>echo "</font> </td>"; <br>} <br>echo "</tr>"; <br>} <br>echo "</table>"; <br>} <br>if($_POST['submit']) yanghui($_POST['givenlines']); <br>?> <br> <br>