Copy codeThe Code is as follows:
<? Php
// Yang Hui 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 triangle custom
Copy codeThe Code is as follows:
<Form method = "post" action = "<? Php echo ($ PHP_SELF);?> ">
Level of the input Yang Hui triangle: <input type = "text" name = "givenlines" size = "5">
<Input type = "submit" name = "submit" value = "">
</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']);
?>