Friday, June 25, 2010

Display a Triangle format Numbers using PHP code

Hi All,
Program to Display following using php code:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

CODE:
Start php here
$k=1;
for($i=0;$i<5;$i++){
for($j=0;$j<=$i;$j++){
echo $k." ";
$k++;
}
echo "
";
}
End php tag

Check out the output...


All d best

24 comments:

  1. can u plz give me code for


    0
    01
    010
    0101
    01010

    ReplyDelete
    Replies
    1. for($i=1; $i<=5; $i++){

      for($j=1; $j<=$i; $j++){

      if($j%2==0){
      echo 0;
      }
      else
      {
      echo 1;
      }

      }
      echo "
      ";
      }

      Delete
    2. This comment has been removed by the author.

      Delete

    3. for($i=1; $i<=5; $i++)
      {
      for($j=1; $j<=$i; $j++)
      {
      if($j%2==0)
      {
      echo 0;
      }
      else
      {
      echo 1;
      }
      }
      echo "";
      }

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. ";
    }
    ?>

    Output :

    0
    0 1
    0 1 0
    0 1 0 1
    0 1 0 1 0

    ReplyDelete
  4. Coding

    $k=1;
    for($i=0;$i<5;$i++){
    for($j=0;$j<=$i;$j++){
    if($j%2==0)
    {
    $k=0;
    }
    else
    {
    $k=1;
    }
    echo $k." ";
    }
    echo "
    ";
    }

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. Code ** Star pattern

      =1;$j--){
      echo "* ";
      }
      echo "
      ";
      }
      ?>

      Delete
  8. can you give a php code to make hexagonal....?

    ReplyDelete
  9. can u plz give me code for

    1
    121
    12321
    1234321
    123454321

    ReplyDelete
  10. plz give this piramit code
    1
    12
    122
    1223
    12233
    122333

    ReplyDelete
  11. plz give this piramit code
    1
    2 6
    3 7 10
    4 8 11 13
    5 9 12 14 15

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. " ;

    }
    ?>

    tag missing ... because
    tag in your code is displayed as line brake in browser.. so please update your post...

    ReplyDelete