ProgrammingHardTCS NQT · Infosys · Capgemini

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
String s = "ABCDEF", r = ""
For i = 0 to 5
    If i mod 2 = 0 Then
        r = s[i] + r
    Else
        r = r + s[i]
    End If
End For
Print r
  1. A. ACEBDF
  2. B. FDBACE
  3. C. ECABFD
  4. D. ECABDF

Correct answer: D. ECABDF

Even-indexed letters are placed at the front (A, C, E end up reversed as E C A) and odd-indexed letters are appended in order (B D F), giving ECABDF.

More Pseudocode and Code Tracing questions

Exams that ask this topic