ProgrammingEasyTCS NQT · Infosys · Accenture
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
String s = "PROGRAM", t = ""
for (each i from 0 to length(s) - 1)
if (i mod 2 == 1)
t = t + s[i]
end if
end for
Print t- A. PORM
- B. ROA
- C. RGA
- D. PGAM
Correct answer: C. RGA
Indexes start at 0: P0 R1 O2 G3 R4 A5 M6, so the odd indexes give R, G, A. PORM is what the even indexes give.
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 i = 1, c = 0 while (i <= 20) i = i 2 c = c + 1 end while Print i, c
- What will be the output of the following pseudocode? Integer n = 6, c = 0 while (n != 1) if (n mod 2 == 0) n = n / 2 else n = 3 n + 1 end…
- What will be the output of the following pseudocode? Integer n = 37 String out = "" while (n > 0) out = out + (n mod 2) n = n / 2 end…
- What will be the output of the following pseudocode? Integer c = 0 for (each n from 2 to 29) Boolean prime = true for (each d from 2 while…
- What will be the output of the following pseudocode? Integer A[5] = {5, 1, 4, 2, 8}, t for (each j from 0 to 3) if (A[j] > A[j + 1]) swap…
- What will be the output of the following pseudocode? Integer A[5] = {64, 25, 12, 22, 11} repeat 2 times, with p = 0, then 1 m = index of…