Course of Raku / Addendum 🆕 / Flow and functions / Subroutines and functional style / Exercises

Digit sum by recursion

Problem

Write a recursive subroutine that adds up the digits of a number, and use it to print the digit sum of 12345 (which is 15).

Example

The program prints:

15

Solution

See the solution

Course navigation

Subroutines and functional style   |   Solution: Digit sum by recursion