c语言哪里错了啊编写程序,输入正整数n,计算 1-2⼀3+3⼀5-4⼀7+5⼀9-6⼀11+…… 的前n项之和

2024-12-03 04:21:04
推荐回答(1个)
回答1:

int n,i;
float sum;
scanf("%d",&n);
sum = 1;
for (i = 2; i <=n; i++)
sum += ( (i%2 == 0)?-1:1)*i/(2*i-1);
printf("%f\n", sum);