GATE Computer ScienceEasyGATE CS (PYQ pattern)

int h(int n) { return n == 0 ? 0 : 2 * h(n / 10) + n % 10; } What is h(2593)?

  1. A. 64
  2. B. 45
  3. C. 57
  4. 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.

More Programming and Data Structures (GATE) questions

Exams that ask this topic