calculating sum of integers

4 visualizzazioni (ultimi 30 giorni)
Aldrich Dias
Aldrich Dias il 22 Feb 2021
Commentato: Aldrich Dias il 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?

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by