i=j=1;
sum=0;
for (count=1;count<=20;count++)
{
t=i;
i+=j;
j=t;
sum=sum+i/j;
}
[此贴子已经被作者于2007-5-31 23:29:34编辑过]
下面是我的程序:
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
float F(int n);
int n;
do
{
printf("input n:");
scanf("%d",&n);
}
while(n<0);
printf("sum=%f",F(n));
system("pause");
return 0;
}
float F(int n)
{
int i;
float fz,fm,f,sum;
if(n==0)
{
sum=0.0;
}
else
{
for(i=1,fz=2,fm=1,sum=0.0;i<=n;i++)
{
f=fz/fm;
fm=fz;
fz=fm+fm/f;
sum+=f;
}
}
return sum;
}
道理我是懂 但不知道怎么实现呢???
#include"stdio.h"
int main(void)
{
int n1=1,n2=2,n3=2,n4=3,i;
int fibonacci1=0,fibonacci2=0;
float sum=0;
for(i=1;i<=20;++i)
{
fibonacci1=n1+n2;
if(n1<n2) fibonacci1=n1;
else fibonacci1=n2;
fibonacci2=n3+n4;
if(n3<n4) fibonacci2=n3;
else fibonacci2=n4;
sum+=(float)fibonacci2/fibonacci1;
}
printf("%f\n",sum);
getch();
return 0;
}
试下符合不?
是这样的吗?
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int n,i;
float fz1,fz2,fm1,fm2,f1,f2,sum;
printf("input n:");
scanf("%d",&n);
for(i=1,fz1=2.0,fz2=3.0,fm1=1.0,fm2=2.0,sum=0.0;i<=n/2;i++)
{
f1=fz1/fm1;
f2=fz2/fm2;
sum+=(f1+f2);
fz1=fz1+fz2;
fz2=fz2+fz1;
fm1=fm1+fm2;
fm2=fm2+fm1;
}
printf("sum=%f",sum);
system("pause");
return 0;
}
2楼大概就这个意思吧!
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int n,i,fz,fm,t;
float sum=0.0;
do
{
printf("input n:");
scanf("%d",&n);
}
while(n<0);
for(i=1,fz=1,fm=1;i<=n;i++)
{
t=fz;
fz+=fm;
fm=t;
sum+=(float)fz/fm;
}
printf("sum=%f",sum);
system("pause");
return 0;
}