How To Make The Number Triangle Type-2 In Php ?

For the fresher it’s easy way to improve the logic and programming syntax. In php we can make the different types numerical triangle. Using for loop or foreach loop we can make a logic to show the triangle, Check below the programming syntax in front of out put:.

1 1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1
1 1 1 1
1 1 1
1 1
1
<?php
for($i=0;$i<=7;$i++){
for($j=7-$i;$j>=1;$j--){
echo "1";
}
echo "<br>";
}
?>
7 6 5 4 3 2 1
6 5 4 3 2 1
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
<?php
for($i=0;$i<=7;$i++){
for($j=7-$i;$j>=1;$j--){
echo $j;
}
echo "<br>";
}
?>
7 7 7 7 7 7 7
6 6 6 6 6 6
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
<?php
for($i=7;$i>=1;$i--){
for($j=$i;$j>=1;$j--){
echo $i."&nbsp;";
}
echo "<br>";
}
?>
3 Comments

Leave a Reply