Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

need help finding the answers for al lproblems Write a \"for loop\" that adds up

ID: 3551000 • Letter: N

Question

need help finding the answers for al lproblems

Write a "for loop" that adds up every other number in an array named Sscore. That is, array elements with index 0,2,4,6,8,10, etc. should be added up and the total displayed. Utilize the count function in the "for loop" so that you know when to stop the loop. Write a "while loop" that does the same thing as question 8 - it adds up the array elements with index 0,2,4,6,8,10, etc. and displays the total. Again utilize the count function in the loop so that you know when to stop the loop.

Explanation / Answer

1) 46


2) 321


3) 101112


4) 36


5) /* Nothing will be displayed */


6) 4


7) 10


8)

$scores=array(24,3,56,67,9,16,55);

$total=0;

for($i=0;$i<count($scores);$i=$i+2){

$total=$total+$scores[$i];

}

echo $total;


9)

$scores=array(24,3,56,67,9,16,55,99,101,6);

$total=0;

$i=0;

while($i<count($scores)){

$total=$total+$scores[$i];

$i=$i+2;

}

echo $total;