ProgrammingModerateTCS NQT · Infosys pattern
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer c = 0
for (i = 1 to 4)
for (j = 1 to 4)
if (j > i)
break
end if
c = c + j
end for
end for
Print c- A. 40
- B. 10
- C. 16
- D. 20
Correct answer: D. 20
break leaves only the INNER loop, so for each i, j runs 1..i: sums 1, 1+2 = 3, 6, 10 → total 20. '10' stops everything at the first break; '40' ignores the break (4 × 10).
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? (&, |, ^ are bitwise AND, OR, XOR; << is a left shift; precedence as in C: << binds…
- What will be the output of the following pseudocode? Function f(Integer n) if (n <= 1) return 1 end if return f(n - 1) + 2 f(n - 2) End…
- What will be the output of the following pseudocode? (Strings are indexed from 0.) String s = "PSEUDOCODE" Integer v = 0 for (i = 0 to…
- What will be the output of the following pseudocode? Integer x = 1 for (k = 1 to 10) x = (x 3) mod 7 end for Print x
- What will be the output of the following pseudocode? (Arrays are indexed from 0.) Integer arr[5] = {3, 1, 4, 1, 5} for (i = 1 to 4) arr[i]…
- What will be the output of the following pseudocode? (calls counts every call, including the first; mod is the remainder.) Integer calls =…