<div class="codetitle"><a style="CURSOR: pointer" data="5682" class="copybut" id="copybut5682" onclick="doCopy('code5682')"> 代码如下:@H_301_1@<div class="codebody" id="code5682">
<?PHP
//杨辉三角
for ($i=6;$i >= 0;$i--)
{
for ($j=$i;$j <= 6;$j++)
{
if ($j <= 6-1)
{
echo "a";
}else
{
echo "
";
}
}
}
?>
@H_301_1@
PHP打印杨辉三角自定义
<div class="codetitle"><a style="CURSOR: pointer" data="97396" class="copybut" id="copybut97396" onclick="doCopy('code97396')"> 代码如下:@H_301_1@<div class="codebody" id="code97396">
<form method="post" action="<?php echo($PHP_SELF); ?>">
输入杨辉三角的阶数:<input type="text" name="givenlines" size="5">
<input type="submit" name="submit" value="打印杨辉三角形">
<?PHP
function yanghui($line)
{
echo "<table>";
for($i=1;$i<=$line;$i++)
{
echo "<tr>";
for($j=1;$j<=$i;$j++)
{
$yh[$i][1]=1;
if ($i==$j) $yh[$i][$j]=1;
else $yh[$i][$j]=$yh[$i-1][$j-1]+$yh[$i-1][$j];
echo "
echo $yh[$i][$j];
echo " </td>";
}
echo "</tr>";
}
echo "</table>";
}
if($_POST['submit']) yanghui($POST['givenlines']);
?>
@H301_1@