Write a program, input a positive integer n and calculate the sum of the first n terms of 1-2/3+3/5-4/7+5/9-6/11+…
#include<stdio.h>
int main()
{
int n,i,deno;
double sum,a;
scanf("%d",&n);
a=1;
sum=0;deno=1;
for(i=1;i<=n;i++)
{
sum=a*(1.0*i/deno)+sum;
deno+=2;
a=-a;
}
printf("%.3f\n",sum);
return 0;
}