Question: The function addDigits(n) takes one argument, n, which is a positive integer , and returns the sum of all the digits in n. Here are
The function addDigits(n) takes one argument, n, which is a positive integer, and returns the sum of all the digits in n.
Here are two example calls to the function:
addDigits(123) # returns 6 addDigits(40305) # returns 12
You must write the function recursively. You may not have for or while loops in your code, nor may you convert to a string. You must complete this using only mathematical operations.
Hint: the mod and integer divide operators are your friends
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
