Write a function that, given a natural number @x@, returns the reduction of its digits.
| C++ | |
| C | |
| Java | |
| Python | |
|
In this exercise, we say that reducing the digits of a number means computing the sum of its digits. If the sum has just one digit, this is already the result. Otherwise, we apply the same process again to the sum, until we get a single digit.
Solve this problem using a recursive function to return the sum of the digits of a natural number @x@.
| C++ | |
| C | |
| Java | |
| Python | |
|
@x@ is a natural number.
Although there is a mathematic trick to solve this problem faster than by adding up its digits, do not use it here.
You only need to submit the required procedure; your main program will be ignored.
Input/Output