GATE Computer ScienceEasyGATE CS (PYQ pattern)
int h(int n) { return n == 0 ? 0 : 2 * h(n / 10) + n % 10; } What is h(2593)?
- A. 64
- B. 45
- C. 57
- D. 19
Correct answer: C. 57
Each step doubles the value built from the leading digits: h(2) = 2, h(25) = 9, h(259) = 27, h(2593) = 57.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- int A(int m, int n) { if (m == 0) return n + 1; if (n == 0) return A(m - 1, 1); return A(m - 1, A(m, n - 1)); } How many calls to A…
- int f(int n); int g(int n) { return n <= 0 ? 1 : f(n - 1) + g(n - 2); } int f(int n) { return n <= 0 ? 0 : g(n - 1) + n; } What does f(6)…
- void r(char s) { if (s[0] == 0 || s[1] == 0) { printf("%s", s); return; } printf("%c%c", s[1], s[0]); r(s + 2); printf("%c", s[0]); } What…
- int t(int n) { return n == 0 ? 0 : n % 3 + 10 t(n / 3); } What is t(97) + t(t(7))?
- 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…