C语言编程求和S=1-1⼀3+1⼀5-1⼀7+…+1⼀n (1⼀n<0.0001)

2024-12-28 01:52:24
推荐回答(1个)
回答1:

#include

int main()
{
int i,exp=1;
double sum=0;

for(i=1;1.0/i>=0.0001;i+=2)
{
sum+=1.0/i*exp; //exp调节符号
exp*=-1;
}

printf("%lf\n",sum);

return 0;
}