Showing posts with label star pattern. Show all posts
Showing posts with label star pattern. Show all posts

Monday, 27 May 2013

How to implement Star pattern in php

In interview, interviewer asked me to write program for star pattern. it was just to check my logic. in this post I am sharing this program.

Inner loop prints line wise and outer loop prints column wise.

<?php
           for($i = 0; $i < 10 ; $i++){
                 for($j = 0; $j <= $i ; $j++){
                       echo '*';
                 }
                 echo '<br/>';
            }
?>


Output of the above code will be

*
**
***
****
*****
******
*******
********
*********
**********

For reverse star pattern click here 

Tuesday, 21 May 2013

How to implement reverse Star pattern in php

In interview, interviewer asked me to write program for reverse star pattern. it was just to check my logic. in this post I am sharing this program.

Inner loop prints line wise and outer loop prints column wise.

<?php
           for($i = 10; $i > 0 ; $i--){
                  for($j = 0; $j < $i ; $j++){
                         echo '*';
                  }
                  echo '<br/>';
            }
?>

Output of the above code will be
**********
*********
********
*******
******
*****
****
***
**
*