Write a function sumDigits(n) that produces the sum of the digits of a nonnegative integer n, when n is written in standard (base 10) notation. For example, sumDigits(24) = 6 since 2 + 4 = 6, and sumDigits(788) = 23 since 7 + 8 + 8 = 23. Use recursion.

Notice that sumDigits(0) = 0. But what about a number that is greater than 0? Notice that sumDigits(12345) = sumDigits(1234) + 5. and sumDigits(788) = sumDigits(78) + 8. In general, for a positive integer n, add the rightmost digit of n to the result produced by sumDigits on the number that you get by removing the rightmost digit of n.

Test your definition by pushing the Compute button. After it works, submit it by pushing the Submit button.

 

  [Language: Cinnameg  Kind: function definition]