printing stars in pyramid shape

Discussion in 'PHP' started by ranji01, May 27, 2011.

  1. #1
    for($i=1;$i<=$n;$i++)
    {
    for($j=1;$j<=$n-$i;$j++)
    echo(" ");
    for($j=1;$j<=2*$i-1;$j++)
    echo(" *");
    echo("<br />");
    }
    its a correct r not .........i work out it....i have some errors.....any one help me.. the output will be
    *
    * *
    * * *
    * * * *
    * * * * *
     
    ranji01, May 27, 2011 IP
  2. IAreOwn

    IAreOwn Active Member

    Messages:
    46
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    95
    #2
    you will only need two loops to achieve this..
     
    IAreOwn, May 27, 2011 IP
  3. Mak3MyDay

    Mak3MyDay Peon

    Messages:
    25
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    for($i = 0; $i < $length; $i++){
    for($j = 0; $j < $i; $j++){
    echo "*";
    }
    echo "\n";
    }
     
    Mak3MyDay, May 27, 2011 IP