Pseudo-code · Question 7 · Medium
What will be the output of the following pseudocode? (Note: for-loop bounds are inclusive.)
Integer i, j, k
Set k = 0
for (i = 1 to 4)
for (j = i to 4)
k = k + 1
end for
end for
Print k
- 16
- 10
- 6
- 4
Answer and explanation
Answer: B. 10
Explanation: For i = 1, 2, 3, 4 the inner loop runs 4, 3, 2 and 1 times, so k = 4 + 3 + 2 + 1 = 10.
Previous: What will be the output of the following pseudocode? (Note: &, | and ^ are… · Next: What will be the output of the following pseudocode?
Practise pseudo-code
Try a fresh set of pseudo-code questions with an explanation after every answer, free and without signing up: Pseudo-code practice. Or sit a full placement mock test.
More pseudo-code questions
- What will be the output of the following pseudocode? (Note: &, | and ^ are…
- What will be the output of the following pseudocode? (Note: / denotes integer…
- What will be the output of the following pseudocode? (Note: &, | and ^ are…
- What will be the output of the following pseudocode?
- What will be the output of the following pseudocode?
- What will be the output of the following pseudocode? (Note: << and >> are…
- What will be the output of the following pseudocode? (Note: / denotes integer…
- What will be the output of the following pseudocode?
- What will be the output of the following pseudocode? (Note: &, | and ^ are…
- What will be the output of the following pseudocode? (Note: for-loop bounds…
More technical & programming practice
C Programming · Java · Python · Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge