#include <stdio.h>
int main()
{
int n,i;
float s1=0,s2=0;
printf(“输入n的值:”);
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2!=0)
s1+=1.0/(2i-1);
else
s2+=-1.0/(2i-1);
}
printf(“前%d项和为%f\n”,n,s1+s2);
}
2023-11-19 13:06:52
#include <stdio.h>
int main()
{
int n,i;
float s1=0,s2=0;
printf(“输入n的值:”);
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2!=0)
s1+=1.0/(2i-1);
else
s2+=-1.0/(2i-1);
}
printf(“前%d项和为%f\n”,n,s1+s2);
}