ProgrammingHardTCS NQT · Infosys · Accenture
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer c = 0
for (each i from 1 to 5)
for (each j from 1 to 5)
if ((i + j) mod 3 == 0)
c = c + 1
end if
end for
end for
Print c- A. 7
- B. 9
- C. 8
- D. 10
Correct answer: B. 9
Pairs with i + j = 3, 6 or 9: sum 3 gives 2 pairs, sum 6 gives 5 pairs, sum 9 gives 2 pairs, total 9.
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 = 84, b = 36, t while (b != 0) t = b b = a mod b a = t end while Print a
- What will be the output of the following pseudocode? Integer A[6] = {5, 1, 7, 3, 9, 2}, s = 0 for (each i from 0 to 5, step 2) s = s +…
- What will be the output of the following pseudocode? Integer a = 0, b = 1, c for (each i from 1 to 6) c = a + b a = b b = c end for Print a
- What will be the output of the following pseudocode? function f(Integer n) if (n <= 1) return n return n + f(n - 2) end function Print f(9)
- What will be the output of the following pseudocode? function f(Integer n) if (n == 0) return 2 return 3 f(n - 1) - 1 end function Print…
- What will be the output of the following pseudocode? Integer x = 5, y, z y = x++ 2 z = ++x + y Print x, y, z