Computer Science EngineeringVery hard

What does f(4795) return for int f(int n){ return n==0 ? 0 : n%10 + f(n/10); }

  1. A. 23
  2. B. 24
  3. C. 25
  4. D. 26

Correct answer: C. 25

It sums the digits: 5+9+7+4 = 25.

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

Exams that ask this topic