calculating sum of integers

4 views (last 30 days)
Aldrich Dias
Aldrich Dias on 22 Feb 2021
Commented: Aldrich Dias on 22 Feb 2021
How to find the sum sum of a intiger for examples if i had an input like 123456789 and the sum of it will be 1+2+3+4+5+6+7+8+9. Is there a special function for this?

Accepted Answer

KSSV
KSSV on 22 Feb 2021
Edited: KSSV on 22 Feb 2021
n = 123456789;
iwant = sum(num2str(n) - '0')
  5 Comments
Aldrich Dias
Aldrich Dias on 22 Feb 2021
hmm i converted it then do I do prod(n)? or prod(n,1:2)?
Aldrich Dias
Aldrich Dias on 22 Feb 2021
i get it now
thank you

Sign in to comment.

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!