How to print a numeric pattern

We can print this pattern in php. In this pattern we divide our program in two parts. In first part we are using two ‘for’ loop to make the above decreasing triangle. The first ‘for’ loop decides the rows and the second ‘for’ loop decides the number of objects in every row. As like above we use same two ‘for’ loops to make lower increasing triangle.

<?php
for($i=1; $i<10; $i=$i+2){ 
    for($j=9; $j>=$i; $j--){
	echo "5";
	}
    echo " ";
}
for($i=1; $i<10; $i=$i+2){
   for($j=1; $j<=$i; $j++){ 
    echo "5"; 
   } 
 echo " "; 
} ?>
Number_series

Leave a Reply