求解
有一分数序列2/1,3/2,5/3,8/5,13/8,21/13…求出前20项之和#include <stdio.h>
void main()
{
double a=1, b=2, c=0;
double sum=0;
int i;
for (i=1;i<=20;i++)
{
printf ("第%d项=%5.2f\n",i,b/a);
sum+=b/a;
c=a;
a=b;
b=b+c;
}
printf("sum=%5.2f",sum);
} 求速度 int main()
{
double a = 1;
double b = 2;
double t = 0;
double sum = 0;
for (int i = 0;i < 20;i++)
{
sum += b/a;
t = a;
a = b;
b = t + b;
}
return 0;
} 楼主 你这个是求代码啊。。。
页:
[1]