ProgrammingVery hardGoldman Sachs OA · TCS Digital
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Function G(Integer n)
if (n == 0)
return 0
end if
return n - G(G(n - 1))
End Function
Print G(10), G(11)- A. 6 7
- B. 5 6
- C. 6 6
- D. 7 8
Correct answer: A. 6 7
Build the table: G(0..11) = 0, 1, 1, 2, 3, 3, 4, 4, 5, 6, 6, 7. For example G(11) = 11 − G(G(10)) = 11 − G(6) = 11 − 4 = 7. Output 6 7.
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? (code(c) gives a letter's character code; 'A' to 'Z' have consecutive codes) String w…
- What will be the output of the following pseudocode? (stop ends the program; arrays are indexed from 0) Integer a[6] = {3, 4, 5, 6, 1, 8}…
- What will be the output of the following pseudocode? (mod keeps the sign of the dividend (as in C); arrays are indexed from 0) Integer…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer calls = 0 Procedure…
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer a[5] = {1, 2, 3, 4, 5}, comps = 0 Procedure…
- What will be the output of the following pseudocode? (mod keeps the sign of the dividend; code/char convert between letters and codes)…