编写一个c语言程序,求下列分数序列的前20项之和:2/1+3/2+5/3+8/5+13/8+
时间: 2023-11-05 13:14:23 浏览: 133
```
#include <stdio.h>
int main() {
int i;
double a = 2, b = 1, c, sum = 0;
for (i = 1; i <= 20; i++) {
sum += a / b;
c = a;
a = a + b;
b = c;
}
printf("前20项之和为:%.2f\n", sum);
return 0;
}
```
运行结果:
```
前20项之和为:32.66
```
阅读全文