Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 19237156Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started