Course of Raku / Addendum 🆕 / Working with data / Numbers and mathematics / Exercises

Digital root

Problem

The digital root of a number is what you get by repeatedly adding its digits until a single digit remains. For 987654: 9+8+7+6+5+4 = 39, then 3+9 = 12, then 1+2 = 3. Compute and print the digital root of 987654.

Example

The program prints:

3

Solution

See the solution

Course navigation

Solution: Greatest common divisor and least common multiple   |   Solution: Digital root