有一分数序列:2/1 3/2 5/3 8/5 13/821/13......求出这个数列的前N项之和,保留两位小数。使用c++
时间: 2023-12-13 11:31:05 浏览: 144
是使用C++计算该分数序列前N项之和的代码,保留两位小数:
```c++
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int n = 20; // 前N项
double a = 2, b = 1, sum = 0, temp;
for (int i = 1; i <= n; i++) {
sum += a / b;
temp = a + b;
b = a;
a = temp;
}
cout << fixed << setprecision(2) << sum << endl;
return 0;
}
```
阅读全文
相关推荐
![c](https://img-home.csdnimg.cn/images/20250102104920.png)
![](https://img-home.csdnimg.cn/images/20250102104920.png)
![vi](https://img-home.csdnimg.cn/images/20250102104920.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![cpp](https://img-home.csdnimg.cn/images/20250102104920.png)
![java](https://img-home.csdnimg.cn/images/20250102104920.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)