ProgrammingHardAccenture · Cognizant pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
String s = "PROGRAM", r = ""
for (i = length(s) - 1 down to 0 step 2)
    r = r + s[i]
end for
Print r
  1. A. MAGOP
  2. B. PORM
  3. C. MROP
  4. D. MRGO

Correct answer: C. MROP

Indices 6, 4, 2, 0 give M, R, O, P. Starting from the end and stepping by 2 picks every other character backwards; stepping forward from 0 would give P, O, R, M.

More Pseudocode and Code Tracing questions

Exams that ask this topic