问答题

编程题请编写函数fun(),它的功能是求Fibonacci数列中小于t的最大的一个数,结果由函数返回。其中Fibonacci数列F(n)的定义为F(0)=0,F(1)=1F(n)=F(n-1)+F(n-2)例如:t=1000时 ,函数值为987。注意:部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。试题程序:#include #include #include int fun(int t){}main(){ int n; clrscr(); n=1000; printf("n=%d, f=%d\n",n, fun(n));}

【参考答案】

int fun(int t) { int a=A,b=A,c=0,i; /*a代表第n-B项,b代表第n-A项,c代表......

(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)