ProgrammingHardAccenture · Cognizant pattern

What will be the output of the following pseudocode? (Arrays are indexed from 0.)

What will be the output of the following pseudocode? (Arrays are indexed from 0.)
Integer arr[6] = {10, 20, 30, 40, 50, 60}
Integer evenSum = 0, oddSum = 0
for (each i from 0 to 5)
    if (i mod 2 == 0)
        evenSum = evenSum + arr[i]
    else
        oddSum = oddSum + arr[i]
    end if
end for
Print evenSum, oddSum, evenSum - oddSum
  1. A. 90 120 -30
  2. B. 120 90 30
  3. C. 100 110 -10
  4. D. 90 120 30

Correct answer: A. 90 120 -30

Even-indexed elements (indices 0,2,4) are 10+30+50=90. Odd-indexed elements (indices 1,3,5) are 20+40+60=120. The difference evenSum-oddSum = 90-120 = -30.

More Pseudocode and Code Tracing questions

Exams that ask this topic