PHP write Yang Hui's triangle instance code _php instance

Source: Internet
Author: User
Tags php print php write
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 '));
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.