• HOW TO MAKE THE TRIANGLE IN PHP?

    Answered

    HOW TO MAKE THE TRIANGLE IN PHP?

    Silver Member Asked on August 24, 2016 in Php.
    Add Comment
  • 3 Answer(s)
    Best answer
    <?php
     
    for($i=0;$i<=9;$i++){

    for ($d=10-$i; $d > 0; $d–) {

    echo “&nbsp;&nbsp;”;
    }
    for($j=1;$j<=$i;$j++){

    echo “&nbsp;”.$i.”&nbsp;”;
    }

    echo “<br>”;

    } ?>

    Silver Member Answered on August 24, 2016.
    Add Comment

    The PHP for loop is used to execute the same part of code a given number of times. Using for loop we can make the different types of number tringle. we can make the looping logic, to execute the same block of code a specified number of times.

    For fresher it’s good practice to learn the programming syntax and to improve the logic. Few numerical triangle programming syntax with output as below.

     

    <?php
    for($i=9;$i>=1;$i–){

    for ($d=0; $d <= 9-$i; $d++) {
    echo “&nbsp;&nbsp;”;
    }

    for($j=$i;$j>=1;$j–){
    echo “&nbsp;”.$i.”&nbsp;”;
    }

    echo “<br>”;

    }
    ?>

     

    HOW TO MAKE THE TRIANGLE IN PHPHOW TO MAKE THE TRIANGLE IN PHP

    Bronze Member Answered on August 25, 2016.
    Add Comment

    <?php
    for($i=0;$i<=9;$i++){
    for ($d=10-$i; $d > 0; $d–) {
    echo “&nbsp;&nbsp;”;
    }
    for($j=1;$j<=$i;$j++){
    echo “&nbsp;”.$i.”&nbsp;”;
    }
    echo “<br>”;
    }
    for($i=8;$i>=1;$i–){
    for ($d=0; $d <= 9-$i; $d++) {
    echo “&nbsp;&nbsp;”;
    }
    for($j=$i;$j>=1;$j–){
    echo “&nbsp;”.$i.”&nbsp;”;
    }
    echo “<br>”;

    }
    ?>

     

    HOW TO MAKE THE TRIANGLE IN PHPHOW TO MAKE THE TRIANGLE IN PHP

    Bronze Member Answered on August 25, 2016.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.