c++编程计算下列调和级数的和: 1+1/2+1/3+1/4+1/5...1/n
时间: 2023-11-20 19:06:46 浏览: 133
以下是C++计算调和级数的和的代码:
```c++
#include <iostream>
using namespace std;
int main() {
int n;
double sum = 0.0;
cin >> n;
for (int i = 1; i <= n; i++) {
sum += 1.0 / i;
}
cout << sum << endl;
return 0;
}
```
阅读全文