ProgrammingHardTCS NQT · Infosys · Capgemini
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
String s = "ABCDEF", r = ""
For i = 0 to 5
If i mod 2 = 0 Then
r = s[i] + r
Else
r = r + s[i]
End If
End For
Print r- A. ACEBDF
- B. FDBACE
- C. ECABFD
- D. ECABDF
Correct answer: D. ECABDF
Even-indexed letters are placed at the front (A, C, E end up reversed as E C A) and odd-indexed letters are appended in order (B D F), giving ECABDF.
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 = 91, b = 35, steps = 0 While a != b If a > b Then a = a - b Else b = b - a…
- What will be the output of the following pseudocode? Integer memo[10] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1} Integer calls = 0…
- What will be the output of the following pseudocode? (^ is exponentiation; / is integer division truncating toward zero. An operator pops…
- What will be the output of the following pseudocode? Integer val[6] = {5, 8, 2, 9, 4, 7} Integer nxt[6] = {3, 5, 0, 1, -1, 4} Integer p =…
- What will be the output of the following pseudocode? Integer a[51] = all zeros (indices 0 to 50) For i = 1 to 50 For j = i to 50 step i…
- What will be the output of the following pseudocode? (ord('A') = 65; the letters are uppercase and the mod keeps every shift inside the…