ProgrammingModerateCognizant GenC Next · Accenture

What will be the output of the following pseudocode? (code(c) gives a letter's character code and char(k) the reverse; 'A'..'Z' have consecutive codes)

What will be the output of the following pseudocode? (code(c) gives a letter's character code and char(k) the reverse; 'A'..'Z' have consecutive codes)
String s = "CODE", r = ""
for (each i from 0 to 3)
    r = r + char((code(s[i]) - code('A') + 3 * i) mod 26 + code('A'))
end for
Print r
  1. A. FRGH
  2. B. CRJM
  3. C. FUMQ
  4. D. CRJN

Correct answer: D. CRJN

Letter i is shifted by 3i: C+0 = C, O+3 = R, D+6 = J, E+9 = N, so CRJN. Shifting every letter by 3 gives FRGH.

More Pseudocode and Code Tracing questions

Exams that ask this topic