Copy Code code as follows:
<?php
Yang Hui's triangle
for ($i =6; $i >= 0; $i-)
{
for ($j = $i; $j <= 6; $j + +)
{
if ($j <= 6-1)
{
echo "<b>a</b>";
}else
{
echo "<br/>";
}
}
}
?>
PHP print Yang Hui's triangle customization
Copy Code code as follows:
<form method= "POST" action= "<?php Echo ($PHP _self);?>" >
Enter the order of the Yang Hui's triangle: <input type= "text" name= "Givenlines" size= "5" >
<input type= "Submit" name= "Submit" value= "Print Yang Hui's triangle" >
</form>
<?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 "<td width=40> <font color= #0000FF >";
echo $yh [$i] [$j];
echo "</font> </td>";
}
echo "</tr>";
}
echo "</table>";
}
if ($_post[' submit ']) Yanghui ($_post[' givenlines '));
?>