计算机二级C语言上机考试编程题及答案3

发布时间:2019-02-04 19:02:12

编程题
请编写函数fun,它的功能是:求Fibonacci数列中大于t(t>3)的最小的一个数,结果由函数返回.其中Fibonacci数列F(n)的定义为:
F(0)=0,F(1)=1
F()=F(n-1) F(n-2)
假如:当 t=1000时, 函数值为1567.
请勿改动主函数动main其它的函数中的任何内容,仅在函数fun花括号中填入所编写的若干语句.
#include
#include
#include
int fun (int t)
{
} 来源:考试大
main()
{
int n;
FILE *out;
n=1000;
printf("n=%d,f=%dn",n,fun(n));
out=fopen ("out.dat", "w");
for (n = 500; n < 3000; n =500)
fprintf(out, "%dn", fun(n));
fclose (out );
}
参考答案:
int fun(int t)
{
int a=1,b=1,c=0,I;
for(i=4;i<=t;i )
{
if(c{
c=a b;
a=b;
b=c;
}
else
break;
}
return c:
}
阅读更多其他试题,请访问生活日记网 用日志记录点滴生活!考试试题频道。
喜欢考试试题,那就经常来哦

该内容由生活日记网提供.