How to add digits of a numeric series
January 16, 2016
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>"; } ?> |
2 Comments
how to creatr this in php help me please
10 8 6 4 2 = 30
10 8 6 4 = 28
10 8 6 = 24
10 8 = 18
10 = 10
———- 110
10 + 8 + 6 + 4 + 2 = 30
10 + 8 + 6 + 4 = 28
10 + 8 + 6 = 24
10 + 8 = 18
10 = 10
———- +110
How this in php