Computer Science EngineeringVery hard

What does f(37) return for int f(int n){ if(n==0) return 0; return f(n/2) + (n%2); }

  1. A. 3
  2. B. 4
  3. C. 2
  4. D. 5

Correct answer: A. 3

The function counts set bits and 37 = 100101 in binary has three of them.

More Algorithms, Data Structures & Programming (ISRO CS) questions

Exams that ask this topic