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.