PHP program to print Triangle number in reverse pattern

1. Program to print Triangle number in reverse pattern

<?php
for($i=6;$i>=1;$i--)
 {
   for($j=$i;$j>=1;$j--)
    {
     echo $j." ";
     if($j==1)
     {
       echo " ";
       echo "<br />";
     }
   }
} 
?>

Output:

6 5 4 3 2 1 
5 4 3 2 1 
4 3 2 1 
3 2 1 
2 1 
1

2. Program to print Triangle number in reverse pattern

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

Output:

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