ProgrammingModerateAccenture · Capgemini
What will be the output of the following pseudocode? (c ? x : y evaluates x if c is true, otherwise y)
What will be the output of the following pseudocode? (c ? x : y evaluates x if c is true, otherwise y)
Integer marks[6] = {92, 75, 60, 88, 45, 75}
Integer A = 0, Bc = 0, C = 0
for (each i from 0 to 5)
Integer m = marks[i]
m >= 85 ? (A = A + 1) : (m >= 70 ? (Bc = Bc + 1) : (C = C + 1))
end for
Print A, Bc, C- A. 2 3 1
- B. 1 2 3
- C. 3 2 1
- D. 2 2 2
Correct answer: D. 2 2 2
The nested conditional checks ≥ 85 first, then ≥ 70: 92 and 88 → A; 75 and 75 → B; 60 and 45 → C. Output 2 2 2.
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? (continue in a do-while loop goes straight to the while test) Integer x = 1, c = 0 do…
- What will be the output of the following pseudocode? (s[i] - '0' turns a digit character into its value; strings are indexed from 0)…
- What will be the output of the following pseudocode? (+ joins strings) Integer count = 0 String third = "" Procedure gen(String s, Integer…
- What will be the output of the following pseudocode? Integer s = 0 for (each i from 1 to 49) if (i mod 3 == 0 OR i mod 5 == 0) s = s + i…
- What will be the output of the following pseudocode? (| is OR, & is AND, << and >> are shifts) Integer c = 0, r, x for (each n from 1 to…
- What will be the output of the following pseudocode? Function iso(String a, String b) Map f = empty, g = empty for (each i from 0 to…