(-1)^k = 1 if k is even, -1 if k is odd so:
for (i=1; i<=N; i++)
{
if (i%2==0)//if it is even
{
sum+=1.0/(i+1);//since i is your k, you just divide by i+1
}
else
{
sum-=1.0/(i+1);
}
}
The rest is simply multiplying, then taking the square root.
Labdabeta
Practically a Master Poster
613 posts since Feb 2011
Reputation Points: 27
Solved Threads: 31
Skill Endorsements: 1
sqrt : DOMAIN ERROR
pie = + NAN
what does this mean?
It means sum is negative, most likely.
deceptikon
Challenge Accepted
3,438 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 56