首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
编写函数fun,其功能是:求Fi-bonacci数列中大于t的最小的数,结果由函数返回。Fibonacci数列F(n)的定义为: F(0)=0,F(1)=1 F(n)=F(n-1)+F(n-2) 例如,当t=1000时,函数值为15
编写函数fun,其功能是:求Fi-bonacci数列中大于t的最小的数,结果由函数返回。Fibonacci数列F(n)的定义为: F(0)=0,F(1)=1 F(n)=F(n-1)+F(n-2) 例如,当t=1000时,函数值为15
admin
2020-10-26
16
问题
编写函数fun,其功能是:求Fi-bonacci数列中大于t的最小的数,结果由函数返回。Fibonacci数列F(n)的定义为:
F(0)=0,F(1)=1
F(n)=F(n-1)+F(n-2)
例如,当t=1000时,函数值为1597。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
1 #include<conio.h>
2 #include<math.h>
3 #include<stdio.h>
4 int fun (int t)
5 {
6
7 }
8 main()
9 {
10 int n ;
11 n=1000;
12 printf(’’n=%d,f=%d\n’’,n,fun(n));
13 }
选项
答案
1 int fun(int t) 2 { 3 int f0=0,f1=1,f; 4 do{ 5 /*根据Fiborlacci数列的定义求数值*/ 6 f=f0+f1; 7 f0=f1;f1=f; 8 } while(f
解析
根据所给数列定义不难发现,该数列最终的结果是由两个数列之和组成,所以可以在循环内部始终把f看成是前两项之和,而f0始终代表第n-2项,f1代表第n-1项。退出循环时得到的数f,就是大于指定数的最小的数。
转载请注明原文地址:https://kaotiyun.com/show/Xt3p777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
以下选项中的编译预处理命令行,正确的是()。
以下选项中,能用作数据常量的是()。
有以下程序:#includemain(){charb[4][10],c;imi,j;for(i=0;i
能从任意一个节点开始没有重复地扫描到所有节点的数据结构是()。
有以下说明语句:char/s="\"Name\\Address\n";指针S所指字符串的长度是()。
有以下程序:#includemain(){inti,array[6]={1,5,0,4};for(i=0;i
有如下程序:#includemain(){inti,data;scanf("%d",&data);for(i=0;i
以下说法中正确的是()。
下列数据结构中,能够按照“先进后出”原则存取数据的是()。
下列关于软件工程的描述中正确的是
随机试题
分封制最早出现的朝代是()。
空调所用制冷技术属于()。
公司策划的首要内容是()
A.长吸式呼吸B.喘息样呼吸C.陈—施呼吸D.比奥呼吸在脑桥上、中部之间横断脑干并同时切断双侧颈迷走神经,动物将出现
国家药品不良反应监测中心报告,某省药品生产企业生产的某药品疗效不确,不良反应大,对该药品应当
根据社会保险法律制度的规定,下列情形应当视同为工伤的是()。
下列关于国债的表述正确的是:
【2015河南邓州】父母均为大学教师的小英从小受家庭的影响,很重视学习。初中期间,当她看书学习时,旁边如有人讲话,就特别反感。进入高中后,小英成绩优秀,担任了班长,但同学们都认为她自以为是,什么工作都必须顺着她,一些同学很讨厌她,为此她感到十分苦恼。如果小
计算机为了通过串行,将数据发送出去,必须(26)。
FromChristianityandthebarbariankingdomsofthewestemergedthemedievalversionofpolitics______inturnevolvedthepol
最新回复
(
0
)