ProgrammingEasyTCS NQT · Infosys · Accenture

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
String s = "PROGRAM", t = ""
for (each i from 0 to length(s) - 1)
    if (i mod 2 == 1)
        t = t + s[i]
    end if
end for
Print t
  1. A. PORM
  2. B. ROA
  3. C. RGA
  4. D. PGAM

Correct answer: C. RGA

Indexes start at 0: P0 R1 O2 G3 R4 A5 M6, so the odd indexes give R, G, A. PORM is what the even indexes give.

More Pseudocode and Code Tracing questions

Exams that ask this topic