calculating sum of integers

2 次查看(过去 30 天)
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?

采纳的回答

KSSV
KSSV 2021-2-22
编辑:KSSV 2021-2-22
n = 123456789;
iwant = sum(num2str(n) - '0')
  5 个评论
Aldrich Dias
Aldrich Dias 2021-2-22
hmm i converted it then do I do prod(n)? or prod(n,1:2)?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by