-
3 Comments
I can't for the life of me figure out how to get this to work for any number n. Any tips?
One way would be to use mod(x,10) to get the ones digit, add that to the sum, then use x=floor(x/10) to lop it off, and iterate until x becomes zero.
Brilliant, thank you! That is most likely the method that I would have ended up using if had I thought of one as well.
Suggested Problems
1406 Solvers
What is the distance from point P(x,y) to the line Ax + By + C = 0?
315 Solvers
Make a run-length companion vector
583 Solvers
464 Solvers
375 Solvers
More from this Author95
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!