English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i need to find a way to know the sum of all the even numbers inside any number for example the sum of all the even numbers of
5 is 6 1,2,3,4,5 2+4 = 6

2006-10-21 12:48:31 · 2 answers · asked by jmpx81 1 in Education & Reference Homework Help

2 answers

To find the amount of even numbers where 'n' is the number of evens and 's' is the bigger number (note - this does not count 0 or s as a number)

s = (n+1)*2
s/2 = n+1
n = (s/2)-1

Example:

6 = (n+1)*2
3 = n+1
n = 2

To find the sum of the first n even numbers you use

2 x ( (n*(n+1) / 2 )

example

s = 2 x ( (n*(n+1) / 2 )
s = 2 x ( (2*(3) / 2 ) // n is 2, as determined in above example
s = 2 x 3
s = 6

2+4=6

2006-10-21 13:49:26 · answer #1 · answered by DoctorScurvy 4 · 0 0

let [x] = the largest integer smaller than x
Sum(2 + 4 + 6 + 8 + 10 + . . . + 2[(n-1)/2]) =
2*(1 + 2 + 3 + 4 + 5 + . . . + [(n-1)/2] )
sum = 2[(n-1)/2]([(n-1)/2]+1)/2
sum = [(n-1)/2]([(n-1)/2]+1)

Another way of writing this is
Sum = (int((n-1)/2))(1+int((n-1)/2))

n, sum
1,2, 0
3,4, 2, 1(1+1)
5,6, 6, 2(2+1)
7,8, 12, 3(3+4)
9,10, 20, 4(4+5)

2006-10-21 21:02:11 · answer #2 · answered by Helmut 7 · 0 0

fedest.com, questions and answers