ProgrammingModerateAccenture · Capgemini
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Function f(Integer n)
if (n <= 1)
return 1
end if
return f(n - 1) + f(n - 2)
end function
Print f(7)- A. 13
- B. 34
- C. 8
- D. 21
Correct answer: D. 21
f(0) = f(1) = 1 gives 1, 1, 2, 3, 5, 8, 13, 21, so f(7) = 21.
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 x = 1, i for (i = 1; i <= 5; i = i + 1) x = (x 3) mod 7 end for Print x
- What will be the output of the following pseudocode? Integer i, s = 0 for (i = 1; i <= 10; i = i + 1) if (i mod 3 == 0) continue end if if…
- What will be the output of the following pseudocode? Integer n = 4021, r = 0 while (n > 0) r = r 10 + (n mod 10) n = n / 10 end while…
- What will be the output of the following pseudocode? Procedure p(Integer a[], Integer x) a[0] = a[0] + x x = x + 100 a[1] = x return x end…
- What will be the output of the following pseudocode? Integer c = 0 Function inc() c = c + 1 return c end function if (inc() > 0 || inc() >…
- What will be the output of the following pseudocode? Integer i = 5, j j = (i++) + (++i) Print i, j (i++ gives the old value and then adds…