用C语言求S=1+1/2+1/3 +1/100
时间: 2023-11-06 16:05:22 浏览: 259
求1+1/2+1/3+1/4+…….+1/100的值
以下是用C语言求S=1+1/2+1/3+...+1/100的代码:
```c
#include <stdio.h>
int main() {
double sum = 0;
for (int i = 1; i <= 100; i++) {
sum += 1.0 / i;
}
printf("S = %lf", sum);
return 0;
}
```
输出结果为:S = 5.187378
阅读全文