#207. 递归计算数字各位之和
递归计算数字各位之和
Sum of Digits (Recursive)
Background
Congcong is currently learning about recursion. He encountered an interesting problem that requires calculating the sum of digits of a non-negative integer, but it must be done recursively, without using loops.
Problem Description
Given a non-negative integer , return the sum of its digits recursively (no loops). Note that modulo (% 10) by yields the rightmost digit (e.g., is ), while integer division (/ 10) by removes the rightmost digit (e.g., is ).
Input Format
Input is given from Standard Input in the following format.
A non-negative integer .
Output Format
Output is printed to Standard Output in the following format.
The sum of the digits of .
Sample
126
9
49
13
12
3
Sample Explanation
For input : The last digit of is (). The remaining part is (). Recursively calculate the sum of digits for , which is . The final result is .
Constraints
. Time limit: second, Memory limit: MiB.