C语言数列求和。已知一个数列如下,求该数列前1000项的和,并 输出S={1,-1/3,1/5,•••,(-1)i+1/2i-1,•••}i=1,2,•••
时间: 2023-10-03 21:08:44 浏览: 174
c语言补习作业+代码.pdf
#include <stdio.h>
int main() {
int i;
double sum = 0.0;
for (i = 1; i <= 1000; i++) {
double term = pow(-1, i) * (1.0 / (2 * i - 1));
sum += term;
}
printf("S = %f\n", sum);
return 0;
}
阅读全文