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"?
- A. zzzzz
- B. abcde
- C. zabcd
- 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.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? (Print writes its value followed by a space.) Function f(n) If n <= 0 Then Return 0…
- What will be the output of the following pseudocode? (Parameters marked ref are passed by reference; the others by value.) Procedure…
- What will be the output of the following pseudocode? (AND has higher precedence than OR, and && style short-circuit evaluation is used…
- What will be the output of the following pseudocode? (^ is bitwise XOR, & is bitwise AND, >> is a right shift; all values are non-negative…
- What will be the output of the following pseudocode? (break leaves only the innermost loop; continue skips to the next iteration of the…
- What will be the output of the following pseudocode? (Arrays are 0-indexed.) Integer a[6] = {4, 7, 1, 9, 3, 6} Integer i = 0 For k = 1 to…