I want to sum a series of integers, say from 1 to 5, but I want to generalise this function. I have seen that the function is:
$$ \text{sum} = \frac{n(n+1)}{2} $$ where $n$ is the number to sum up to
So for $n=5$, i.e. $1 + 2 + 3 + 4 + 5$, the sum is $15$.
My question is, how could I (without knowing by heart) work out that function myself?
Let $$S = 1 + 2 + 3 + ... + n$$
Rearrange to the form $$S = (n + 1) + ((n-1) + 2) + ... + (n - (n - 1) + n) =(n+1)+(n+1)+...(n+1)$$
So there are $n/2$ terms (because we've paired them off), so $$S = \frac{n}{2}(n+1) = \frac{n(n+1)}{2}$$