ProgrammingHardAccenture · Capgemini
What will be the output of the following pseudocode? (strings are indexed from 0; + joins strings)
What will be the output of the following pseudocode? (strings are indexed from 0; + joins strings)
String s = "ABCDEF", r = ""
Integer k = 8, n = length(s)
for (each i from 0 to n - 1)
r = r + s[(i + k) mod n]
end for
Print r- A. CDEFAB
- B. GHIJKL
- C. EFABCD
- D. ABCDEF
Correct answer: A. CDEFAB
Reading from index (i + 8) mod 6 = (i + 2) mod 6 rotates the string left by 8 mod 6 = 2 places: CDEFAB. Rotating right by 2 would give EFABCD.
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? Integer a[7] = {1, 3, 2, 4, 1, 5, 2}, c = 0 for (each i from 1 to 5) if (a[i] > a[i…
- What will be the output of the following pseudocode? Integer a[5] = {1, 2, 3, 4, 5} Integer odd = 0, even = 1, s = 0, ans = 0 // counts of…
- What will be the output of the following pseudocode? (& is bitwise AND on 32-bit integers) Function pow4(Integer n) return n > 0 AND (n &…
- What will be the output of the following pseudocode? (& is AND, ^ is XOR, << is left shift) Integer x = 7, m = 1 while ((x & m) != 0) x =…
- What will be the output of the following pseudocode? Integer printed = 0 Procedure perm(String s, Integer l) // s is passed by value if (l…
- What will be the output of the following pseudocode? Integer t[4][4] = {{2}, {3, 4}, {6, 5, 7}, {4, 1, 8, 3}} // row r has r + 1 numbers…