1. ## Series output problem

I need to print the following series :

1-1/2+1/3-1/4......+-1/n

where n will be given by user.

I have written the code as :

Code:
```int main()
{
int i,n;
float sum=0.0;
printf("\n Enter the no. of terms for summation : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2==0)
i=-i;
sum=sum+1.0/i;
}
printf("\n Summation is : %4.2f",sum);

return 0;
}```

Only for n=1 I am getting an output, but frm n=2 onward no output.

Please tell me where i am going wrong.

2. Code:
```for(i=1;i<=n;i++)
...
i=-i;```
What do you think is going to happen to your for loop, if you negate i ?

Try this code and see what happens
Code:
```int sign = 1;
for ( i = 0 ; i < 10 ; i++ ) {
printf("Sign = %d\n", sign );
sign = -sign;
}```

3. Code:
```for(i=1;i<=n;i++)
...
i=-i;```
What do you think is going to happen to your for loop, if you negate i ?
Oppss....That was a pathetic mistake i made..!!!

Try this code and see what happens
Code:
```int sign = 1;
for ( i = 0 ; i < 10 ; i++ ) {
printf("Sign = %d\n", sign );
sign = -sign;
}```
Thankss Salem...It worked out beautifully for me...Thank u so so much...