Skip to main content

Practice · 3 of 5

Recursive digit sum

CHALLENGE
Difficulty: beginner+25 XP

Implement int dsum(int n) recursively: sum of n's decimal digits. 0 → 0; otherwise the last digit (n % 10) plus dsum of the rest (n / 10).

Back to lesson: Practice: Recursion reps