1. series converges to 2

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 have checked it many times, but i cannot find the error.
Can someone help me to find out the error.

Thank you !!

2. Code:
```#include <stdio.h>
#include <math.h>

/* main returns int */
void main(void)
{
int i=1;
double single;
double sum=1.0;

/* should let .000001 be a #define
while ( fabs(single>0.000001) ) {
if (i%2==1)
/* should be single = -1.0/(2.0*i+1.0);
What you have does integer division so you get
single = 0 each time.
*/
single=-1/(2*i+1);
else
/* also needs to be changed */
single=1/(2*i+1);
sum+=single;
i++;
}
printf("the sum is converges to %lf \n", sum);

/* return 0 */
}```

3. thanks, Nick.

My code is

#include <stdio.h>
#include <math.h>
#define X 0.000001

int main(void)
{
int i=1;
double single=0;
double sum=1.0;

while ( fabs(single>X) ) {
if (i%2==1)
single=-1.0/(2.0*i+1.0);
else
single=1.0/(2.0*i+1.0);
sum+=single;
i++;
}
printf("the sum is converges to %lf \n", sum);

return 0;
}

Anything wrong here ??

4. a:

and fabs(single > x) wvaluates to 0 initially bcoz u init single to 0

try initialising it to 1

also X needs to be increased

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

converges to .785897 not 2