How do you write pascal tringle in php using while loop?

1 answer

Answer

1003040

2026-08-01 14:01

+ Follow

function pascal($depth){

$row = array(1);

while($depth > 0){

$newRow = array(1);

for($n = 1; $n < count($row); $n++){

$newRow[] = $row[$n - 1] + $row[$n];

}

$newRow[] = 1;

$depth --;

echo implode(' ', $newRow) . "\n";

$row = $newRow;

}

}

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.