Yang Hui Triangle PHP Write Yang Hui Triangle Example Code

WBOY
Release: 2016-07-29 08:46:07
Original
3087 people have browsed it

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 "
";
}
}
}
?> action="">
Input the order of Yang Hui's triangle:

< input type="submit" name="submit" value="Print Yang Hui triangle">

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']);
?>



The above introduces the Yang Hui triangle example code for writing Yang Hui triangle in PHP, including the content of Yang Hui triangle. I hope it will be helpful to friends who are interested in PHP tutorials.


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template