ProgrammingModerateAccenture · Cognizant pattern
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer x = 0
for (each i from 1 to 100)
if (i mod 4 == 0)
continue
end if
if (i > 10)
break
end if
x = x + i
end for
Print x- A. 43
- B. 55
- C. 40
- D. 45
Correct answer: A. 43
The loop adds 1 to 10 but skips 4 and 8: 55 - 12 = 43. At i = 11 (not a multiple of 4) the break ends the loop, and 12 is never reached.
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 = 10, b = 3, c = 0 while (a >= b) a = a - b c = c + 1 end while Print c, a
- 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? Integer c = 0 for (each i from 1 to 5) for (each j from 1 to 5) if (j > i) break end…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Integer n = 2048, c = 0, d…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Function f(Integer n) if (n…
- 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…