有一数列:2/1,3/2,5/3,8/5,…求出这个数列前10项和。c语言
时间: 2023-12-13 12:20:59 浏览: 68
#include <stdio.h>
int main() {
int i, n = 10;
double a = 2, b = 1, sum = 0, temp;
for (i = 1; i <= n; i++) {
sum += a / b;
temp = a;
a = a + b;
b = temp;
}
printf("前%d项和为%f", n, sum);
return 0;
}
阅读全文