Home >Backend Development >PHP Tutorial >Write Yang Hui triangle example code in PHP_PHP tutorial

Write Yang Hui triangle example code in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:27:251324browse

Copy code The code is as follows:

//Yang Hui Triangle
for ($i=6; $i >= 0;$i--)
{
for ($j=$i;$j <= 6;$j++)
{
if ($j < = 6-1)
{
echo "a";
}else
{
echo "
";
}
}
}
?>

PHP printing Yang Hui triangle customization
Copy code The code is as follows:


Enter the order of Yang Hui's triangle: < ;input type="text" name="givenlines" size="5">


function yanghui($line)
{
echo "";
for($i=1;$i<=$line; $i++)
{
echo "";
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 "";
}
echo "
";
echo $yh[$i][$j];
echo "
";
}
if($_POST['submit']) yanghui($_POST['givenlines']);
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323807.htmlTechArticleCopy the code code as follows: ?php //Yang Hui Triangle for ($i=6;$i = 0;$ i--) { for ($j=$i;$j = 6;$j++) { if ($j = 6-1) { echo "ba/b"; }else { echo "br /"; } } } ? PHP print Yang Hui triangle custom...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn