ProgrammingVery hardInfosys SP · Goldman Sachs OA
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)
Function f(Integer n)
if (n == 0)
return 1
end if
return f(n / 2) + f(n / 3)
End Function
Print f(12)- A. 13
- B. 12
- C. 21
- D. 8
Correct answer: B. 12
Build up: f(0) = 1, f(1) = 2, f(2) = 3, f(3) = 4, f(4) = 5, f(6) = 7, f(12) = f(6) + f(4) = 7 + 5 = 12.
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? (ref means the argument is passed by reference; other parameters are copies)…
- What will be the output of the following pseudocode? (/ is integer division) Stack st = empty for each token t in "6 2 3 + - 3 8 2 / + "…
- What will be the output of the following pseudocode? Integer a = 144, b = 89, t, steps = 0 while (b != 0) t = a mod b a = b b = t steps =…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; , / and mod have equal…
- What will be the output of the following pseudocode? (& is bitwise AND, >> is right shift) Integer s = 0, x, t for (each i from 1 to 16) x…
- What will be the output of the following pseudocode? Integer m[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} for (each i from 0 to 2) for…