ProgrammingModerateTCS Digital · Infosys InfyTQ
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer i, s = 0
for (i = 1; i <= 10; i = i + 1)
if (i mod 3 == 0)
continue
end if
if (i > 8)
break
end if
s = s + i
end for
Print s- A. 24
- B. 45
- C. 27
- D. 37
Correct answer: C. 27
Added values: 1, 2, 4, 5, 7, 8 (multiples of 3 skipped, loop stops at 10 because 9 is skipped and 10 > 8): total 27.
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 n = 4021, r = 0 while (n > 0) r = r 10 + (n mod 10) n = n / 10 end while…
- What will be the output of the following pseudocode? Procedure p(Integer a[], Integer x) a[0] = a[0] + x x = x + 100 a[1] = x return x end…
- What will be the output of the following pseudocode? Integer c = 0 Function inc() c = c + 1 return c end function if (inc() > 0 || inc() >…
- What will be the output of the following pseudocode? Integer i = 5, j j = (i++) + (++i) Print i, j (i++ gives the old value and then adds…
- What will be the output of the following pseudocode? Integer n = 1000, c = 0 while (n != 0) n = n & (n - 1) c = c + 1 end while Print c (&…
- What will be the output of the following pseudocode? Function g(Integer n) if (n == 0) return 0 end if if (n mod 2 == 0) return g(n - 1) +…