ProgrammingHardTCS NQT · Infosys · Capgemini
What will be the output of the following pseudocode? (break leaves only the innermost loop; continue skips to the next iteration of the innermost loop.)
What will be the output of the following pseudocode? (break leaves only the innermost loop; continue skips to the next iteration of the innermost loop.)
Integer s = 0
For i = 1 to 6
For j = i to 6
If (i + j) mod 3 = 0 Then Continue
If i * j > 20 Then Break
s = s + i * j
End For
End For
Print s- A. 157
- B. 151
- C. 89
- D. 27
Correct answer: C. 89
Each inner loop skips pairs whose sum is a multiple of 3 and abandons the row once i*j exceeds 20, but the outer loop still moves to the next i. Adding the surviving products row by row gives the printed total.
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? (Arrays are 0-indexed.) Integer a[6] = {4, 7, 1, 9, 3, 6} Integer i = 0 For k = 1 to…
- What will be the output of the following pseudocode? String s = "ABCDEF", r = "" For i = 0 to 5 If i mod 2 = 0 Then r = s[i] + r Else r =…
- What will be the output of the following pseudocode? Integer a = 91, b = 35, steps = 0 While a != b If a > b Then a = a - b Else b = b - a…
- What will be the output of the following pseudocode? Integer memo[10] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1} Integer calls = 0…
- What will be the output of the following pseudocode? (^ is exponentiation; / is integer division truncating toward zero. An operator pops…
- What will be the output of the following pseudocode? Integer val[6] = {5, 8, 2, 9, 4, 7} Integer nxt[6] = {3, 5, 0, 1, -1, 4} Integer p =…