I use a while loop to find the following series converges to 2.

1- 1/3 + 1/5 -1/7 + ...

My Code is :

#include <stdio.h>

#include <math.h>

void main(void)

{

int i=1;

double single;

double sum=1.0;

while ( fabs(single>0.000001) ) { /* exit when single small */

if (i%2==1)

single=-1/(2*i+1);

else

single=1/(2*i+1);

sum+=single;

i++;

}

printf("the sum is converges to %lf \n", sum);

}

I get the answer 1 instead of the correct one 2.

I have checked it many times, but i cannot find the error.

Can someone help me to find out the error.

Thank you !!