DonkeyMails.com: No Minimum Payout
DonkeyMails.com: No Minimum Payout

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 

No comments:

Post a Comment