-
3 Comments
Richard
on 4 Aug 2014
I can't for the life of me figure out how to get this to work for any number n. Any tips?
Tim
on 4 Aug 2014
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.
Richard
on 7 Aug 2014
Brilliant, thank you! That is most likely the method that I would have ended up using if had I thought of one as well.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!