ProgrammingHardCognizant GenC Next · Accenture
What will be the output of the following pseudocode? (mod keeps the sign of the dividend; code/char convert between letters and codes)
What will be the output of the following pseudocode? (mod keeps the sign of the dividend; code/char convert between letters and codes)
String s = "DEF", r = ""
Integer shift = -5
for (each i from 0 to length(s) - 1)
Integer k = ((code(s[i]) - code('A') + shift) mod 26 + 26) mod 26
r = r + char(code('A') + k)
end for
Print r- A. YZA
- B. IJK
- C. ABC
- D. XYZ
Correct answer: A. YZA
Shifting back 5 wraps past A: D (3) → −2 → 24 = Y, E → 25 = Z, F → 0 = A. The + 26 fixes the negative remainder, giving YZA.
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? (All variables are integers, so / is integer division) Integer x = 1221, rev = 0…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer fact[10], count = 0…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer n = 50, c = 0, p = 2…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer n = 36, s = 0 for…
- What will be the output of the following pseudocode? (& is bitwise AND) Integer mask = 13, s, c = 0 s = mask while (s > 0) c = c + 1 s =…
- What will be the output of the following pseudocode? (integers are 32-bit; & is AND, << and >> are shifts) Integer x = 45 Integer y = (x…