ProgrammingHardTCS NQT · Infosys · Capgemini

What will be the output of the following pseudocode? (ord('A') = 65; the letters are uppercase and the mod keeps every shift inside the alphabet, so shifts larger than 26 wrap around.)

What will be the output of the following pseudocode? (ord('A') = 65; the letters are uppercase and the mod keeps every shift inside the alphabet, so shifts larger than 26 wrap around.)
String s = "WIZARD", out = ""
Integer k = 4
For each character ch in s
    Integer c = (ord(ch) - 65 + k) mod 26
    out = out + char(c + 65)
    k = k + 3
End For
Print out
  1. A. APJNHW
  2. B. AMDEVH
  3. C. ANFHZM
  4. D. ZOIMGV

Correct answer: A. APJNHW

The shift grows by 3 for each letter: 4, 7, 10, 13, 16, 19. W+4 = A, I+7 = P, Z+10 = J, A+13 = N, R+16 = H, D+19 = W, giving APJNHW.

More Pseudocode and Code Tracing questions

Exams that ask this topic