• How to add digits of a numeric series?

    How to add digits of a numeric series?

    Bronze Member Asked on August 26, 2016 in Php.
    Add Comment
  • 1 Answer(s)
    Best answer

    We can print a numeric pyramid series and also can print the sum of every row using php code. We need two ‘for’ loops to print this pattern in php. First ‘for’ loop is used for rows and second ‘for’ loop is used for numbers in a row. We use ‘if’ conditions to add a ‘+’ sign between the numbers also some variables to store the sum of a row.

    <?php
    $k=1; $b=0;
    for($i=1; $i<=5; $i++){
    for($j=1; $j<=$i; $j++){
    if($k<$j){
    echo “+”;
    }
    echo $j;
    }
    $a=$j – 1;
    $b=$a + $b;
    echo “=”.$b;
    echo “<br>”;
    }
    ?>

    HOW TO ADD DIGITS OF A NUMERIC SERIES

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

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