Write a program to print the pascal triangle pattern in php language
ADVERTISEMENTS
Write a program to print the pascal triangle pattern in php language. There are you will learn how to print the pascal triangle pattern.
Follow this example to print this pattern through a php program:
<?php
// Write a program to print the
// pascal triangle pattern in PHP language
$r = 7;
$co = 1;
echo "-----This is the pascal triangle pattern-----\n\n";
for ($i = 0; $i < $r; $i++) {
echo "\t";
for ($ws = 1; $ws <= $r - $i; $ws++) {
echo " ";
}
for ($j = 0; $j <= $i; $j++) {
if ($j == 0 || $i == 0)
$co = 1;
else
$co = $co * ($i - $j + 1) / $j;
echo $co . " ";
}
echo "\n";
}
?>
Output:
-----This is the pascal triangle pattern-----
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
Tags:
# pascal triangle in php using recursion
# explain the logic of the pascal triangle in php
# pascal triangle in php using array
# php program to print pyramid pattern of numbers