Formula for sum of digits of a number

Click For Summary

Discussion Overview

The discussion revolves around finding a formula for calculating the sum of the digits of a number, specifically focusing on 2-digit and 3-digit numbers. Participants explore various methods, including both algorithmic and manual approaches, and express interest in solutions that do not rely on computer programming.

Discussion Character

  • Exploratory
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant seeks a formula for the digit sum of 2-digit and 3-digit numbers, expressing difficulty in isolating the second digit.
  • Another participant suggests using the DIV\MOD algorithm, which can generate each digit for any base and sum them, assuming the context is base 10.
  • A participant questions whether a manual, pencil-and-paper method exists for calculating the digit sum, rather than relying on computer algorithms.
  • A proposed method involves repeatedly applying the modulo operation to extract digits and summing them, with an example calculation provided for clarity.
  • One participant presents a formula that combines terms to express the digit sum, including a method for handling powers of ten.
  • A later reply expresses satisfaction with the derived formula, suggesting a more compact mathematical representation using summation notation.

Areas of Agreement / Disagreement

Participants do not reach a consensus on a single formula or method for calculating the digit sum. Multiple approaches are discussed, and some participants express uncertainty about the clarity and applicability of the proposed methods.

Contextual Notes

Some participants indicate limitations in their understanding of the more technical explanations, suggesting that the discussion may depend on varying levels of mathematical background among contributors.

greg9381
Messages
5
Reaction score
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 = (\frac{x}{10})\lfloor + something. But I don't know how to isolate y.
 
Physics news on Phys.org
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 = (\frac{x}{10})\lfloor + 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
 
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.
 
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.
 
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: (\left\lfloor\frac{x}{10}\right\rfloor) + (x -10(\left\lfloor\frac{x}{10}\right\rfloor))
...

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

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

For powers of ten where \frac{x}{10^{n}} 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
 
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}
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K