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

Consider the following array: int[] a = { 1, 2, 3, 4, 5, 4, 3, 2, 1, 0 }; What i

ID: 3739138 • Letter: C

Question

Consider the following array:

int[] a = { 1, 2, 3, 4, 5, 4, 3, 2, 1, 0 };

What is the value of total after the following loops complete?

a) int total = 0;
for (int i = 0; i < 10; i++) { total = total + a[i]; }

b) int total = 0;
for (int i = 0; i < 10; i = i + 2) { total = total + a[i]; }

c) int total = 0;
for (int i = 1; i < 10; i = i + 2) { total = total + a[i]; }

d) int total = 0;
for (int i = 2; i <= 10; i++) { total = total + a[i]; }

e) int total = 0;
for (int i = 1; i < 10; i = 2 * i) { total = total + a[i]; }

f) int total = 0;
for (int i = 9; i >= 0; i--) { total = total + a[i]; }

g) int total = 0;
for (int i = 9; i >= 0; i = i - 2) { total = total + a[i]; }

h) int total = 0;
for (int i = 0; i < 10; i++) { total = a[i] - total; }

Explanation / Answer

here are the answers after execting theeach code..

===============================================================

a:    25
b:    13
c:    12
d:   -259613674      //garbage value
e:    11
f:     25
g:    12
h:    -1

==============================================================

Kindly Check and Verify Thanks..!!!

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