Question: Matlab question 6) Functions III Write a function add_digits(n), which computes the sum of all digits of an integer number n with a maximum of
Matlab question

6) Functions III Write a function add_digits(n), which computes the sum of all digits of an integer number n with a maximum of 20 digits. (For instance: add_digits(137) = 1+3+ 7 = 11). The following algorithm does exactly this: 1. Generate a vector p with all powers of 10, i.e. 10 to 1020 2. Divide n by p and round the result to the next integer (Hint: Look at floor()) 3. For every entry compute the remainder of the division. (Hint: Look at rem()) 4. The sum of all remainders is the final result. Test your implementation on 1234567890, 18916 and 19237156
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
