GATE Computer ScienceHardGATE CS (PYQ pattern)
int t(int n) { return n == 0 ? 0 : n % 3 + 10 * t(n / 3); } What is t(97) + t(t(7))?
- A. 12311
- B. 10142
- C. 10331
- D. 20222
Correct answer: C. 10331
t writes n in base 3 but reads the digits as a decimal number, least significant digit in the units place. 97 = 81 + 2*9 + 3 + 1 = 10121 in base 3. t(7) = 21 (7 = 2*3 + 1), and t(21): 21 = 2*9 + 1*3 + 0 gives 210. Sum 10121 + 210 = 10331.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- int g(int a, int b) { return b == 0 ? a : g(b, a % b); } How many calls to g (including the first) does g(610, 987) make, and how many…
- int w(int n) { if (n < 0) return 0; if (n == 0) return 1; return w(n - 1) + w(n - 3) + w(n - 4); } What does w(10) return, and how many…
- int x = 0; void q(int n) { if (n > 0) { x += n; q(n - 1); printf("%d ", x); if (n > 2) q(n - 2); } } What does q(4) print?
- Integers 1, 2, 3, 4, 5 are pushed on an initially empty stack in this order; pops may be interleaved with pushes at any time. How many of…
- The integers 1 to 6 are pushed in this order onto a stack that can hold at most 2 elements at any moment; pops may be interleaved with…
- A circular queue stores items in an array of 8 slots (indices 0 to 7) and keeps two fields, front (index of the first item) and count…