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

Need help with this array solution: i know the answer is 32 13 9 3 24 16, my que

ID: 3810578 • Letter: N

Question

Need help with this array solution: i know the answer is 32 13 9 3 24 16, my question is how is it outputting this  

i got stuck on:   sum = sum + array[0] ( so sum = 0+20) then onto the next statement   array[0] = 20.0 / 20 * 100 ? i got 100 but the first line is 32 what am i missing?

QUES What is the output of the following code? int array 120 8, 6, 2, 15 10 int sum 3 0; for (int 0; i array length it sum +J: array [i] for (int i 0; i array length; it array [i] (int) (((double) array[i]) sum 100) for (int i 0; i array length. i++) System. out.print (array Cij 32.78688524590164 13. 114754098360656 9.8360655 737 70492 3.2 78 68 852459 0164 24.5 901 639 3442623 16.39 34426229 5082 3200 000 0 0 0 0 0 0 o 32 1393 24 16

Explanation / Answer

there is for loop it doesot go to next statement,the first for loop will executes till the condition in the for loop becomes false,i.e condition is i<array.length.

so it is in seques:

i=0;initial value;condition is i<array.length

First sum=sum+array[i]

i++;

so 0+20 is stored in sum and i is incremented and then again

sum=20+array[1] ==>20+8=28

increment i,i=2

sum=28+arrray[2]==>28+6=34 and loop executes and the final sum is sum of all elemens of array=61

Then the next for loop whihc calculates the individual aray element by the total sum *100.here divide each elementby 61 and multiply with 100.

and last for loop will print the array elements.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote