c语言1+1/2+1/3+...+1/100
时间: 2023-11-18 12:06:10 浏览: 108
C#求1-1/2+1/3-1/4+…….-1/100的值
以下是求解1+1/2+1/3+...+1/100的C语言程序:
```c
#include <stdio.h>
int main() {
int n = 100;
float sum = 0;
for (int j = 1; j <= n; j++) {
sum = sum + 1.0 / j;
}
printf("前%d项的和为%.3f", n, sum);
return 0;
}
```
阅读全文