1+1/2+1/3+1/4+1/5+1/6+1/7+1/8+1/9+1/10用c语言i--
时间: 2024-01-29 12:02:41 浏览: 150
以下是使用C语言计算1+1/2+1/3+1/4+1/5+1/6+1/7+1/8+1/9+1/10的代码:
```c
#include <stdio.h>
int main() {
double sum = 0.0;
int i;
for (i = 1; i <= 10; i++) {
sum += 1.0 / i;
}
printf("sum = %.2f", sum);
return 0;
}
```
输出结果为:sum = 2.93
阅读全文