Mathematica How Can Mathematica Calculate the Digital Sum of a Number in Base 10?

AI Thread Summary
To calculate the sum of the digits of a number in base 10 using Mathematica, the correct command is to use `Plus @@ IntegerDigits[number]`. For example, to find the sum of the digits of 380234, you would input `Plus @@ IntegerDigits[380234]`, which outputs 20. The discussion highlights that defining a function like `s[3^14, 10] := Plus @@ IntegerDigits[3^14, 10]` is unnecessary for a quick calculation, as it requires evaluation after definition. Instead, directly inputting the command without defining a function yields immediate results.
amcavoy
Messages
663
Reaction score
0
Which command in Mathematica will give me the sum of the digits of a number in base 10? Thanks.
 
Physics news on Phys.org
So you want it to give you something like this:

Input: 380234
Output: 20
Input: 32138
Output: 17

?
 
Yes, exactly. Do you know how that is done?
 
I had already found that; nothing happens when I plug that into Mathematica. I entered:

Code:
s[3^14, 10] := Plus @@ IntegerDigits[3^14, 10]
and then nothing came out. Is this the correct way to enter it? For this example I was trying to compute the sum of the digits of 314 in base 10. Thanks.
 
That's because you're attempting to define a "function" and haven't asked Mathematica to do anything with it.

For a quick answer, just copy and paste the right side into an input line and evaluate it.
 

Similar threads

Replies
5
Views
3K
Replies
20
Views
7K
Replies
7
Views
2K
Replies
1
Views
3K
Replies
10
Views
2K
Replies
5
Views
2K
Back
Top