使用循环计算 s=1/1!−1/2!+1/3!−1/4!+…+1/99!−1/100! 的值 c语言
时间: 2023-11-19 13:06:18 浏览: 192
求1+1/2+1/3+1/4+…….+1/100的值
以下是使用循环计算 s=1/1!−1/2!+1/3!−1/4!+…+1/99!−1/100! 的值的C语言代码:
```c
#include <stdio.h>
int main() {
int n = 100;
double sum = 0, factorial = 1;
for (int i = 1; i <= n; i++) {
factorial *= i;
if (i % 2 == 0) {
sum -= 1 / factorial;
} else {
sum += 1 / factorial;
}
}
printf("Sum = %lf", sum);
return 0;
}
```
阅读全文