Junior — Senior
Determining the digital root of a given number
livecode
Task condition
Digital root is the result of repeatedly summing the digits of a number until a single-digit result is obtained. Given a non-negative integer n, you need to iteratively sum all its digits; if the resulting sum has more than one digit, the process repeats until only a single digit remains. A non-negative integer is input. Examples: 16 --> 1 + 6 = 7 942 --> 9 + 4 + 2 = 15 --> 1 + 5 = 6 132189 --> 1 + 3 + 2 + 1 + 8 + 9 = 24 --> 2 + 4 = 6 493193 --> 4 + 9 + 3 + 1 + 9 + 3 = 29 --> 2 + 9 = 11 --> 1 + 1 = 2