Slapshot136
Divide et impera
- Reaction score
- 471
so I have a series that looks like this:
r^0 + r^2 + r^4 + r^6 + ... r^2n = ?
how can I derive a formula for what the sum is equal to?
similar example:
r^0 + r^1 + r^2 + r^3 + ... r^n = (r^(n+1)-1) / (r-1)
P.S. - here is a working c++ example
r^0 + r^2 + r^4 + r^6 + ... r^2n = ?
how can I derive a formula for what the sum is equal to?
similar example:
r^0 + r^1 + r^2 + r^3 + ... r^n = (r^(n+1)-1) / (r-1)
P.S. - here is a working c++ example
Code:
int calculate(int n, int r)
{
int sum = 1;
int r2 = r*r;
int temp = 1;
for (int i = 1; i <= n; i++)
{
temp = temp * r2;
sum += temp;
}
return sum;
}