The recursive formula is: sum(n)=(nmod10)+sum(⌊n/10⌋) This says: the sum of digits equals the last digit plus the sum of the remaining digits.
For example, sum(1234)=4+sum(123), and sum(123)=3+sum(12), continuing until you reach a single digit. Each recursive call shrinks n by removing its last digit, moving you toward the base case.