7、有一分数序列 2/1.3/2.5 /3求出这个教列前20项之和。(用do--while 语句完成)
时间: 2024-01-17 17:05:11 浏览: 143
以下是使用 do-while 语句计算这个分数序列前20项之和的代码:
```c
#include <stdio.h>
int main() {
double numerator = 2.0, denominator = 1.0, fraction, sum = 0.0;
int i = 1;
do {
fraction = numerator / denominator;
sum += fraction;
numerator += i + 1;
denominator += i;
i++;
} while (i <= 20);
printf("The sum of the first 20 terms of the sequence is: %.2f", sum);
return 0;
}
```
输出结果为:
```
The sum of the first 20 terms of the sequence is: 32.66
```
阅读全文