# [SOLVED] Sum of numbers between 2 numbers, formula?

Printable View

• Apr 10th 2010, 02:58 AM
KavX
[SOLVED] Sum of numbers between 2 numbers, formula?
Hi,

Sorry if this is in the wrong section, I did maths a year and a bit back in high school and im doing computing at uni, and I'm not sure on the exact formula I need.

I need it to double check that my program is outputting the right sum.

I need the formula to calculate the sum of the numbers between 200 and 300 inclusively.

the sum my program is giving me is 25250

I cant even remember doing this with numbers being inclusive or exclusive.

so could someone please explain the difference between inclusive and exclusive numbers, and the formula I need to be using?

thx
• Apr 10th 2010, 03:07 AM
Nebuchadnezzar
You probably remember the sum formula for the first natural numbers

$\displaystyle \frac{n(n+1)}{2}$ then in your example for calculating the sum of numbers between x and y we get:

$\displaystyle S(x,y) \, = \, \frac{x(x+1)}{2} - \frac{y(y+1)}{2} \qquad x>y$
• Apr 10th 2010, 03:13 AM
KavX
so with this formula is it calculating like

201 + 202.... +299
or
200+201... +300

thx
• Apr 10th 2010, 03:27 AM
Nebuchadnezzar
Seems like i made some slight mistake in my previous solution, the correct should be

$\displaystyle S(x,y) \, = \, \frac{x(x+1)}{2} \, - \, \frac{y(y-1)}{2} \qquad x>y$

Lets say S(204,200) this should be equal to

200 + 201 + 202 + 203 + 204 = 1010

Which indeed this formula gives us.

S(300,200)=25250
• Apr 10th 2010, 03:39 AM
KavX
fantastic, so my program is outputting the correct answer! thx for the help much appreciated.

I do have another question or need another formula, I would like to remove the mutiples of 7.

from what I can remember this may have something to do with geometric or was it arithmatic sequences.

so the first multiples would be 203, 210, 217
and the difference between them is obviously 7,

so now I need to find the sum of the multiples of 7 between 2 numbers, so I can subtract it from my total of 25250
• Apr 10th 2010, 03:50 AM
drumist
Quote:

Originally Posted by KavX
fantastic, so my program is outputting the correct answer! thx for the help much appreciated.

I do have another question or need another formula, I would like to remove the mutiples of 7.

from what I can remember this may have something to do with geometric or was it arithmatic sequences.

so the first multiples would be 203, 210, 217
and the difference between them is obviously 7,

so now I need to find the sum of the multiples of 7 between 2 numbers, so I can subtract it from my total of 25250

The multiples of 7 would range from 203 (7*29) through 294 (7*42). So, this sum would be

203 + 210 + 217 + ... + 294

which is the same as

7*29 + 7*30 + 7*31 + ... + 7*42

We can factor the 7 out, thus:

7*(29 + 30 + 31 + ... + 42)

So, if you can find the sum of the numbers between 29 and 42, and multiply that by 7, you will have calculated the sum of all the multiples of 7 between 200 and 300.

Of course you want to subtract this from your original answer.
• Apr 10th 2010, 03:53 AM
KavX
thx for the help again, just to double check if im doing this right

would my answer be 3276?

i got 468 when finding the sum between those 2 numbers, after multiplying by 7 i got 3276
• Apr 10th 2010, 04:16 AM
Nebuchadnezzar
$\displaystyle \sum\limits_{n = y}^m {7n} = - \frac{{7\left( {y - x + 1} \right)\left( {y + x} \right)}}{2}$

$\displaystyle S(x,y) = 25250 + \frac{{7\left( {y - x + 1} \right)\left( {y + x} \right)}}{2} \qquad x>y$

Enjoy ;)
• Apr 10th 2010, 04:22 AM
KavX
using your formula Nebuchadnezzar, i get 3479 as the sum of the multiplys of 7

so 25250 -3479 = 21771

are those correct?
thx for the help
• Apr 10th 2010, 04:47 AM
drumist
Quote:

Originally Posted by KavX
thx for the help again, just to double check if im doing this right

would my answer be 3276?

i got 468 when finding the sum between those 2 numbers, after multiplying by 7 i got 3276

A quick an easy way to find the sum of all integers in a given range is to multiply the average of the first and last term by the number of terms.

So, in this case:

$\displaystyle \frac{29+42}{2} \cdot 14 = 497$