Formula for sum of digits of a number

In summary: %20-%209\sum_{n=1}^{\infty}{\left%20\lfloor\frac{x}{100^n}%20\right%20\rfloor}%20-%209\sum_{n=1}^{\infty}{\left%20\lfloor\frac{x}{1000^n}%20\right%20\rfloor}%20-%209\sum_{n=1}^{\infty}{\left%20\lfloor\frac{x}{10000^n}%20\right%20\rfloor}}%20-%20\left(\frac{x}{10^{n+1}}
  • #1
greg9381
5
0
Any ideas on this? I googled it and got only answers inolving Excel, C++, etc...
A formula for finding the digit sum of a 2-digit number, or only a 3-digit number, would also be interesting.

I thought I had a start with this: For a 2-digit number xy, the sum of the digits = [itex](\frac{x}{10})\lfloor[/itex] + something. But I don't know how to isolate y.
 
Physics news on Phys.org
  • #2
greg9381 said:
Any ideas on this? I googled it and got only answers inolving Excel, C++, etc...
A formula for finding the digit sum of a 2-digit number, or only a 3-digit number, would also be interesting.

I thought I had a start with this: For a 2-digit number xy, the sum of the digits = [itex](\frac{x}{10})\lfloor[/itex] + something. But I don't know how to isolate y.

Hey greg9381 and welcome to the forums.

The best way to answer this for any base is to use the DIV\MOD algorithm. This will generate each digit for each base-position for any base and then you can simply sum all the base-position components and get an answer.

You can apply this say for a number in base 2, base 16, or base 10. From the sounds of it, you want to apply this algorithm to base 10. Also I'm going to assume you have a whole number: if you don't just remove the remainder (term after the decimal point) and treat this result as a normal whole number.

Take a look at this:

http://www.cut-the-knot.org/recurrence/conversion.shtml
 
  • #3
Well, I'm not very advanced (AB calc in high school) so I can't completely understand the article, but it seems to be a way to find the digit sum using a computer? To clarify, I'm wondering if it's possible to have a formula that can be done with pencil and paper, not computers.
 
  • #4
greg9381 said:
Well, I'm not very advanced (AB calc in high school) so I can't completely understand the article, but it seems to be a way to find the digit sum using a computer? To clarify, I'm wondering if it's possible to have a formula that can be done with pencil and paper, not computers.

The basic idea is very simple and goes a little something like this:

Take a number n. Do the following until you get n = 0.

Set i = 1
Calculate a(i) = n MOD 10. Let n = n - a(i). n = n / 10.
If n = 0 then we are done. If not then increase i by 1 and go back to the previous step.

Then if you want the sum simply add up all the a(i)'s and that will give you your sum.

This is for base-10, but if you want to do it for any base then just replace 10 with the base you are working with.

Quick example. Let n = 231.

a(1) = 231 MOD 10 = 1. 231 - 1 = 230. 230/10 = 23 which is not zero so i = 2.
a(2) = 23 MOD 10 = 3. 23 - 3 = 20. 20/10 = 2 which is not zero so i = 3.
a(3) = 2 MOD 10 = 2, 2-2 = 0, 0/10 = 0 so we stop.

Now add up all a(i)'s to get a(1) + a(2) +a(3) = 1 + 3 + 2 = 5 which is what we expect.
 
  • #5
I got it.

About thirty minutes of non-continuous free time and a half sheet of paper gave me this:
For any whole number "x":
1 digit: x
2 digits: ([itex]\left\lfloor[/itex][itex]\frac{x}{10}[/itex][itex]\right\rfloor[/itex]) + (x -10([itex]\left\lfloor[/itex][itex]\frac{x}{10}[/itex][itex]\right\rfloor[/itex]))
...

After awhile, I realized I could combine like terms, and this is what I got:

x - 9([itex]\left\lfloor[/itex][itex]\frac{x}{10}[/itex][itex]\right\rfloor[/itex]) - 9([itex]\left\lfloor[/itex][itex]\frac{x}{100}[/itex][itex]\right\rfloor[/itex]) - 9([itex]\left\lfloor[/itex][itex]\frac{x}{1000}[/itex][itex]\right\rfloor[/itex]) - 9([itex]\left\lfloor[/itex][itex]\frac{x}{10000}[/itex][itex]\right\rfloor[/itex]) ...

For powers of ten where [itex]\frac{x}{10^{n}}[/itex] is less than 1, those items become 0.

To use this formula quickly, you may wish to use decimals and do the floor function in your head.

i.e.: Find the sum of the digits of 345854:
345854 - 9(34585) - 9(3458) - 9(345) - 9(34) - 9(3) = 29
 
  • #6
Perfect! So it could be expressed as this:
latex.codecogs.com/gif.latex?x%20-%209\sum_{n=1}^{\infty}{\left%20\lfloor%20\frac{x}{10^n}%20\right%20\rfloor}
 

1. What is the formula for finding the sum of digits of a number?

The formula for finding the sum of digits of a number is to add all the individual digits of the number together.

2. How do I apply this formula to a specific number?

To apply the formula, you would need to break down the number into its individual digits and then add them together. For example, if the number is 123, you would add 1+2+3=6.

3. Can this formula be used for decimal numbers?

Yes, this formula can be used for both whole numbers and decimal numbers. Simply follow the same steps of breaking down the number into its individual digits and adding them together.

4. Is there a faster way to find the sum of digits of a number?

Yes, there are several shortcuts or tricks that can be used to quickly find the sum of digits of a number. Some examples include using patterns or using the digital root method.

5. What is the significance of finding the sum of digits of a number?

Finding the sum of digits of a number can be helpful in various mathematical calculations and can also be used as a check for accuracy in calculations. Additionally, it can also reveal patterns or properties of a number.

Similar threads

Replies
4
Views
182
  • Precalculus Mathematics Homework Help
Replies
19
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • General Math
Replies
2
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
5
Views
2K
  • Computing and Technology
Replies
4
Views
743
Replies
4
Views
385
Replies
3
Views
1K
  • Calculus and Beyond Homework Help
Replies
32
Views
2K
Replies
4
Views
918
Back
Top