How to Add the Individual digits of a result ?
Show older comments
>> 789*4567
ans =
3603363
I want to add each element of the ans :
i.e., >> 3+6+0+3+3+6+3
ans =
24
Help me how to do this?
Accepted Answer
More Answers (1)
Image Analyst
on 28 Jun 2014
Try this:
theNumber = 3603363
theString = num2str(theNumber)
theSum = sum(theString - '0')
(I hope I didn't just do your homework.)
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!