ProgrammingModerateTCS NQT · Wipro Turbo

Consider the pseudocode (letters a..z are 0..25; mod wraps within the alphabet). r = "" for i = 0 to length(s) - 1: r = r + letter((index(s[i]) + 2*i + 1) mod 26) What does it produce for s = "zyxwv"?

  1. A. zzzzz
  2. B. abcde
  3. C. zabcd
  4. D. bcdef

Correct answer: B. abcde

The shifts are 1, 3, 5, 7, 9. z(25)+1 = 26 -> a; y(24)+3 = 27 -> b; x(23)+5 = 28 -> c; w(22)+7 = 29 -> d; v(21)+9 = 30 -> e. Shifts of i alone give zzzzz.

More Pseudocode and Code Tracing questions

Exams that ask this topic