ProgrammingHardWipro NLTH · Cognizant GenC
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer i, j, c = 0
for (i = 1; i <= 6; i = i + 1)
for (j = 1; j <= 6; j = j + 1)
if (j > i)
break
end if
if ((i + j) mod 2 == 1)
continue
end if
c = c + 1
end for
end for
Print c- A. 21
- B. 9
- C. 11
- D. 12
Correct answer: D. 12
For each i, j runs from 1 to i; counting j with the same parity as i gives 1, 1, 2, 2, 3, 3 = 12.
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 = 48, b = 18, steps = 0 while (a != b) if (a > b) a = a - b else b = b - a…
- What will be the output of the following pseudocode? Integer a[15] = {2, 5, 8, 12, 16, 23, 38, 45, 56, 72, 91, 99, 101, 110, 120} Integer…
- What will be the output of the following pseudocode? Integer a[4][4], i, j, s = 0 for (i = 0; i < 4; i = i + 1) for (j = 0; j < 4; j = j +…
- What will be the output of the following pseudocode? Integer calls = 0 Function F(Integer n) calls = calls + 1 if (n < 2) return n end if…
- What will be the output of the following pseudocode? List L = [1, 2, 3, 4, 5, 6, 7] Integer idx = 0, k = 3 while (size(L) > 1) idx = (idx…
- What will be the output of the following pseudocode? Function gcd(Integer a, Integer b) while (b != 0) t = a mod b a = b b = t end while…