PHP写杨辉三角实例代码_PHP

WBOY
Release: 2016-06-01 12:14:59
Original
1416 people have browsed it
复制代码 代码如下:
//杨辉三角
for ($i=6;$i >= 0;$i--)
{
for ($j=$i;$j {
if ($j {
echo "a";
}else
{
echo "
";
}
}
}
?>

PHP打印杨辉三角自定义
复制代码 代码如下:

输入杨辉三角的阶数:


function yanghui($line)
{
echo "";
for($i=1;$i{
echo "";
for($j=1;$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']);
?>

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!