calculating sum of integers

2 vues (au cours des 30 derniers jours)
Aldrich Dias
Aldrich Dias le 22 Fév 2021
Commenté : Aldrich Dias le 22 Fév 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?

Réponse acceptée

KSSV
KSSV le 22 Fév 2021
Modifié(e) : KSSV le 22 Fév 2021
n = 123456789;
iwant = sum(num2str(n) - '0')
  5 commentaires
Aldrich Dias
Aldrich Dias le 22 Fév 2021
hmm i converted it then do I do prod(n)? or prod(n,1:2)?
Aldrich Dias
Aldrich Dias le 22 Fév 2021
i get it now
thank you

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by