ProgrammingModerateAccenture · Capgemini

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 a[3] = {1, 3, 8}, b[4] = {2, 7, 9, 10}, c[7]
Integer i = 0, j = 0, k = 0
while (i < 3 AND j < 4)
    if (a[i] <= b[j])
        c[k] = a[i]
        i = i + 1
    else
        c[k] = b[j]
        j = j + 1
    end if
    k = k + 1
end while
while (i < 3) { c[k] = a[i]; i = i + 1; k = k + 1 }
while (j < 4) { c[k] = b[j]; j = j + 1; k = k + 1 }
Print c[3], c[6]
  1. A. 7 10
  2. B. 8 10
  3. C. 3 10
  4. D. 7 9

Correct answer: A. 7 10

Merging gives {1, 2, 3, 7, 8, 9, 10}. The middle (index 3) is 7 and the last is 10: 7 10.

More Pseudocode and Code Tracing questions

Exams that ask this topic