calculating sum of integers

9 visualizaciones (últimos 30 días)
Aldrich Dias
Aldrich Dias el 22 de Feb. de 2021
Comentada: Aldrich Dias el 22 de Feb. de 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?

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by