Embercode
✕
Recursion and BacktrackingCoding problems

Recursion and Backtracking: coding problems

Write a program that reads the input and prints the answer. Run checks it against every test, including hidden ones.

0 of 7 solved

  • A shop prints receipt numbers that can be very large. The cashier wants a quick check: add up the digits of the number. For example, 9875 gives 9 + 8 + 7 + 5 = 29.

    Write a recursive method that returns the sum of the decimal digits of a number, then print that sum.

    **Constraints:** 0 <= n <= 10^18. Use long for the number.

    Input. One line with one integer n.

    Output. One line with the sum of the digits of n.

    Example 1 input

    9875
    

    Output

    29
    

    Example 2 input

    0
    

    Output

    0