Site icon 腳本酒

php 演算法(三角形之聖誕樹)


function solution($s){

for ($i=1; $i<=$s; $i++) {
//顯示空格
for ($k=$i;$k<$s;$k++) {
echo "&nbsp&nbsp";
}
//顯示*
for($j=0;$j<$i*2-1;$j++){
echo "*";
}
echo "<br>";
}
for ($k1=1;$k1<$s;$k1++) {
echo "&nbsp&nbsp";
}
echo "*";

}

solution(5);

結果如下:

Exit mobile version