MATLAB Answers

calculating sum of integers

28 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
i get it now
thank you

Sign in to comment.

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!

Translated by