计算多项式s=1/2+2/3+3/5+5/8+8/13+……前100项之和,保留两位小数,用c语言做
时间: 2023-06-16 18:03:20 浏览: 191
DATA_CONV_ENCODE.rar_3/4码率_4 3 2 1_conv_lowere77_码率
5星 · 资源好评率100%
可以使用循环来计算每一项的值并累加,其中分母和分子都是斐波那契数列的一部分:
```c
#include <stdio.h>
int main() {
int n = 100;
double sum = 0.0;
double a = 1.0, b = 2.0, c;
for (int i = 1; i <= n; i++) {
sum += b / a;
c = a + b;
a = b;
b = c;
}
printf("The sum of the first %d terms is %.2f\n", n, sum);
return 0;
}
```
输出结果为:
```
The sum of the first 100 terms is 45.52
```
阅读全文