有一个分数序列1⼀2,2⼀3,3⼀5,5⼀8,8⼀13,13⼀21......求这个序列的前20项之和。帮忙啊!C语言编程

求大神帮助
2024-12-20 17:53:48
推荐回答(5个)
回答1:

#include
main()
{
double a[20],b[20];
int i=0;
double sum=0;
a[0] = 1;
b[0] = 2;
a[1] = 2;
b[1] = 3;
for (i=2;i<20;i++)
{
a[i] = a[i-2] + a[i-1];
b[i] = b[i-2] + b[i-1];
}
for (i=0;i<20;i++)
{
sum += a[i]/b[i];
}
printf("%f\n",sum);
}

回答2:

int c,sum=0,i;
int a=1;
int b=2;
sum+=a/b
for(i=0;1++;i<19)
{
c=a+b;
sum+=b/c;
a=b;
b=c;
}
大概这意思

回答3:

#include 
int main(void)
{
int a = 1, b = 2, i;
double sum = 0;
for (i = 0; i < 20; i++) {
sum += (double)a / b;
b += a;
a = b - a;
}
printf("sum=%lf\n", sum);
return 0;
}

回答4:

void main()
{
char i;
double a=1,b=2;
double d=0;
for(i=0;i<20;i++)
{
d=d+a/b;
a=b;
b=b+a;
}
printf("%f",d);
}

回答5:

好难。。。。我也想知道啊