I have to create a sum on php that goes like this
1+2-3+4-5+6-7+8-8+10
For far I got this:
<?php
$start = 1;
$n=10;
$sum = 0;
for($i=$start; $i <=$n; $i++){
$sum += $i;
}
echo "sum from " . $start . " to " . $n . " = " . $sum;
?>
I understand the php code is adding but I'm unsure how to switch between adding and subtracting as the sum continues. Thank you for answering my query.
8-8should be8-9? - B. Desai