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

1. Suppose you have an array of seven int values called test containing the foll

ID: 675216 • Letter: 1

Question

1. Suppose you have an array of seven int values called test containing the following data:

Trace the execution of the following code:

int x = 0;

int y = 0;

for (int i = 0; i < 7; i++)

{

    if (test[i] % 2 == 1)

{

y += test[i];

    }

    else

     {

x += test[i];

}

}

What is the value of x when this loop is done?

2. After the following code snippet executes, what would be the value of the variable eq?

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

bool eq = (a == b);

Select one:

True

False

3. Trace the execution of the following code and answer the question below:

int fib[] = { 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 };

for (int i = 1; i < 5; i++)

{

fib[0] = fib[ fib[i] ];

fib[ fib[i] ] = fib[i];

fib[i] = fib[0];

}

cout << "fib[0] = " << fib[0];

What value is printed by the code above (i.e., what is the content of fib[0] after executing

the code)?

index 0 1 2 3 4 5 6 test 8 6 0 3 4 9 2

Explanation / Answer

1. x is the sum of even numbers in array
x = 8 + 6 + 0 + 4 + 2 = 20

2. eq = true

3. 5