ProgrammingEasyAccenture · Cognizant pattern
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
for (i = 10; i >= 1; i = i - 3)
Print i
end for- A. 10 7 4 1
- B. 10 7 4
- C. 10 7 4 1 -2
- D. 7 4 1
Correct answer: A. 10 7 4 1
i takes 10, 7, 4, 1; the next value −2 fails i >= 1, so the loop stops. Stopping at 4 treats the condition as i > 1; printing −2 checks the condition after printing.
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? (/ is integer division; + on strings concatenates.) Integer n = 100 String s = ""…
- What will be the output of the following pseudocode? (/ is integer division.) Function f(Integer n) if (n == 0) return 0 end if return (n…
- What will be the output of the following pseudocode? (/ is integer division.) Integer n = 25, z = 0 while (n > 0) n = n / 5 z = z + n end…
- What will be the output of the following pseudocode? Integer s = 0 for (i = 1 to 30) if (i mod 4 == 0) continue end if if (i mod 7 == 0)…
- What will be the output of the following pseudocode? (Byte variables are 8-bit unsigned: they hold 0–255 and arithmetic wraps modulo 256.)…
- What will be the output of the following pseudocode? (Strings are indexed from 0; swap exchanges two characters.) String s = "ABCDEF"…