ProgrammingModerateAccenture · Cognizant pattern
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer s = 0
for (each i from 1 to 3)
for (each j from 1 to 3)
if (i == j)
continue
end if
s = s + i * j
end for
end for
Print s- A. 11
- B. 14
- C. 22
- D. 36
Correct answer: C. 22
Over all 9 pairs, the sum of i × j is (1 + 2 + 3)² = 36. The skipped diagonal is 1 + 4 + 9 = 14. 36 - 14 = 22. Each unordered pair is counted twice, so 11 is the trap.
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? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right…
- What will be the output of the following pseudocode? (Arrays are indexed from 0.) Integer arr[5] = {1, 2, 3, 4, 5} Integer t for (each k…
- What will be the output of the following pseudocode? Integer s = 0, i = 1 while (i <= 20) s = s + i i = i 2 + 1 end while Print s
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Function g(Integer n) if (n…
- What will be the output of the following pseudocode? (Arrays are indexed from 0.) Integer arr[6] = {5, -2, 3, -1, 4, -6} Integer s = 0, m…
- What will be the output of the following pseudocode? Integer x = 7, y = 3 Print x mod y y + x / y