Given a positive integer n, find the sum of its digits. For example, if n=1234, the answer is 1+2+3+4=10.
You can split n into: - Last digit: n % 10 - Remaining digits: n // 10 Then the sum is: last digit + sum of the rest. plaintext Input: 1234 Output: 10 Input: 9 Output: 9 Input: 100 Output: 1 Before reading the solution, identify the base case yourself. When is the answer obvious without recursion?