ProgrammingModerateAccenture · TCS NQT
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer n = 0, c = 0
do
c = c + 1
n = n + 3
while (n mod 5 != 0)
Print c, n- A. 4 12
- B. 5 15
- C. 6 18
- D. 1 3
Correct answer: B. 5 15
The do-while body runs before the test: n goes 3, 6, 9, 12, 15 and stops at the first multiple of 5, after 5 passes. Output 5 15.
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 cat[0..6] cat[0] = 1 for (each i from 1 to 6) cat[i] = 0 for (each j from 0…
- What will be the output of the following pseudocode? Integer a[6] = {3, 1, 2, 6, 4, 5}, swaps = 0, m, n = 6 for (each i from 0 to n - 2) m…
- What will be the output of the following pseudocode? Integer a[6] = {5, 2, 4, 6, 1, 3}, shifts = 0, key, j for (each i from 1 to 5) key =…
- What will be the output of the following pseudocode? (code(c) gives a letter's character code and char(k) the reverse; 'A'..'Z' have…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer n = 987654321, c = 0…
- What will be the output of the following pseudocode? Integer a[6] = {1, 2, 4, 5, 7, 9} Integer i = 0, j = 5, c = 0 while (i < j) if (a[i]…