ProgrammingModerateCapgemini · Infosys pattern
What will be the output of the following pseudocode? (All variables are integers, so / is integer division.)
What will be the output of the following pseudocode? (All variables are integers, so / is integer division.)
Integer a = 15, b = 4 Print (a / b) * b + a mod b
- A. 12
- B. 3
- C. 16
- D. 15
Correct answer: D. 15
a / b = 3, so 3 × 4 + 15 mod 4 = 12 + 3 = 15. For integers, (a / b) × b + a mod b always gives back a.
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 = 5, b = 0 if (a > 3 && b != 0) Print "X" else if (a > 3 || b > 0) Print…
- What will be the output of the following pseudocode? Function fun(Integer n) if (n < 3) return n end if return fun(n - 1) + 2 fun(n - 3)…
- 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? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right…
- What will be the output of the following pseudocode? Integer x = 0 for (each i from 1 to 5) for (each j from 1 to i) if ((i + j) mod 2 ==…
- What will be the output of the following pseudocode? Function fun(Integer n) if (n > 0) fun(n - 1) Print n fun(n - 1) end if End Function…