#K36917. Single Digit Sum
Single Digit Sum
Single Digit Sum
You are given an integer n
(which may be negative) and your task is to compute its single digit sum, also known as the digital root. The digital root is obtained by repeatedly summing the digits of the number until only one digit remains. Note that the negative sign is ignored (i.e. we work with the absolute value of n
).
For example, for n = 38
:
The sum of the digits is: 3 + 8 = 11
Then, the sum of the digits of 11
is: 1 + 1 = 2
, so the digital root is 2
.
Mathematically, you can define the process as follows:
$$\text{Let } n = |n|, \quad \text{and iterate} \quad n = \sum_{\text{digit } d \text{ in } n} d \quad \text{until } n < 10. $$inputFormat
The input consists of a single integer n
provided via standard input (stdin).
Note: The number can be negative, but its sign should be ignored when computing the digital root.
outputFormat
Output a single digit which is the digital root of n
. The result should be printed to standard output (stdout).
38
2
</p>