In Maple and Mathematica, how can I compute the sum of the digits that make up a number?
In Maple, to compute the sum of the digits that make up a number, use these commands:
> sod := n -> add( i,i = convert(n, base, 10)): > sod(16293);With Mathematica, use these commands:
In[1]:= SumOfDigits[n_] := Apply[Plus, IntegerDigits[n]] In[2]:= SumOfDigits[16293] Out[2]= 21IntegerDigits[n] is the same as
ToExpression[Characters[ToString[n]]] .
For more about statistical and mathematical software, email the UITS Stat/Math Center, visit the center's web page, or phone 812-855-4724 (IUB) or 317-278-4740 (IUPUI). The center is located in Bloomington at 410 N. Park Avenue, and is open for consultation by appointment Monday-Friday 9am-5pm.
This is document aejj in domain all.
Last modified on March 17, 2011.
Last modified on March 17, 2011.







