当前位置: 代码迷 >> C语言 >> 令我费解的c语言编程题目...菜鸟望给于指点!
  详细解决方案

令我费解的c语言编程题目...菜鸟望给于指点!

热度:143   发布时间:2007-08-19 08:12:36.0
令我费解的c语言编程题目...菜鸟望给于指点!

请编写函数fun(),它的功能是求fibonacci数列中小于t的最大的一个数,结果由函数返回。其中fibonacci数列F(n)的定义为:
F(0)=0, F(1)=1
F(n)=F(n-1)+F(n-2)
例如: t=1000时,函数值为987.


#include <conio.h>
#include <math.h>
#include <stdio.h>
int fun(int t)
{int a=1,b=1,c=0,i;
{c=a+b;
a=b;
b=c;
}
while (c<t);
c=a;
return c;
}
main()
{int n;
clrscr();
n=1000;
printf("n=%d,f=%d\n",n,fun(n));
}
怎么就无法按要求运行呢?

搜索更多相关的解决方案: c语言  

----------------解决方案--------------------------------------------------------
int fun(int t)
{int a=1,b=1,c=0,i;
do//你漏了吧
{c=a+b;
a=b;
b=c;
}
while (c<t);
c=a;
return c;
}


----------------解决方案--------------------------------------------------------

可是这样还是无法运行啊?


----------------解决方案--------------------------------------------------------

那是程序本身的问题了


----------------解决方案--------------------------------------------------------
#include <math.h>
#include <stdio.h>
int fun(int t)
{
int a=1,b=1,c=0;
do
{
c=a+b;
a=b;
b=c;
}
while (c<t);
c=a;
return c;
}
main()
{
int n;
n=1000;
printf("n=%d,f=%d\n",n,fun(n));
getch();
}
这个可以运行的
----------------解决方案--------------------------------------------------------
很乱的一段代码,思路不清晰,格式乱,而且有BUG~~~~~
----------------解决方案--------------------------------------------------------

真诚谢谢所有楼上的指点!


----------------解决方案--------------------------------------------------------
  相关解决方案