Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

recursive function

>>> def sum_digits(n):
        """Return the sum of the digits of positive integer n."""
        if n < 10:
            return n
        else:
            all_but_last, last = n // 10, n % 10
            return sum_digits(all_but_last) + last
Source by composingprograms.com #
 
PREVIOUS NEXT
Tagged: #recursive #function
ADD COMMENT
Topic
Name
7+7 =