有一分数序列:1/2,2/3,3/5,5/8,8/13,13/21...用c语言求出这个数列的前20项之和。
时间: 2023-12-13 20:07:01 浏览: 13
#include <stdio.h>
int main() {
int i;
double a = 1, b = 2, sum = 0;
for (i = 1; i <= 20; i++) {
sum += b / a;
double temp = a + b;
a = b;
b = temp;
}
printf("前20项之和为:%lf", sum);
return 0;
}
阅读全文
相关推荐
![c](https://img-home.csdnimg.cn/images/20250102104920.png)
![vi](https://img-home.csdnimg.cn/images/20250102104920.png)
![c](https://img-home.csdnimg.cn/images/20250102104920.png)
![](https://img-home.csdnimg.cn/images/20250102104920.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![java](https://img-home.csdnimg.cn/images/20250102104920.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![cpp](https://img-home.csdnimg.cn/images/20250102104920.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![cpp](https://img-home.csdnimg.cn/images/20250102104920.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)