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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related General Management Questions!