PHP program to print Diamond Triangle number

Program to print Diamond Triangle number

<?php
for($i=1; $i<=5; $i++)
  {
    for($k=5;$k>=$i;$k--)
     {
       echo "&nbsp;";
     }
      for($j=1; $j<=$i; $j++)
         { echo $i." ";
           if($j==$i)
            {
                echo " ";
                echo "<br/>";
            }
         }
   } 
?>

Output:

     1 
    2 2 
   3 3 3 
  4 4 4 4 
 5 5 5 5 5 
Leave a reply
Captcha Click on image to update the captcha .