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- A. APJNHW
- B. AMDEVH
- C. ANFHZM
- 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.
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? (Arrays are 0-indexed.) Integer a[7] = {5, 1, 4, 2, 8, 0, 3} Integer swaps = 0…
- What will be the output of the following pseudocode? (Static scoping: a name used inside a procedure refers to the variable visible where…
- What will be the output of the following pseudocode? (Arrays are 0-indexed.) Integer a[7] = {1, 2, 4, 5, 7, 9, 10} Integer i = 0, j = 6, c…
- What will be the output of the following pseudocode? (Division is integer division; arrays are 0-indexed.) Integer a[9] = {2, 3, 3, 3, 5…
- What will be the output of the following pseudocode? (& is bitwise AND; arrays are 0-indexed.) Integer m[4][4] For i = 0 to 3 For j = 0 to…
- What will be the output of the following pseudocode? Function J(n, k) If n = 1 Then Return 0 Return (J(n - 1, k) + k) mod n End Function…