首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有以下程序: #include int fun(int X) { int P; if(x==0 || x==1) return(3); P=x—fun(x一2); return P;
有以下程序: #include int fun(int X) { int P; if(x==0 || x==1) return(3); P=x—fun(x一2); return P;
admin
2020-06-16
27
问题
有以下程序:
#include
int fun(int X)
{
int P;
if(x==0 || x==1)
return(3);
P=x—fun(x一2);
return P;
}
main()
{
printf(“%d\n”,fun(7));
}
程序执行后的输出结果是( )。
选项
A、2
B、3
C、7
D、0
答案
A
解析
因为fun(int x)是一个递归函数,所以主函数中fun(7)经过3次递归调用,其过程可以描述为“fun(7)=7一fun(5)=7一(5一fun(3))=7一(5一(3一fun(1)))=7一(5一(3—3))=7—5=2”,所以最后输出结果为2。因此A选项正确。
转载请注明原文地址:https://kaotiyun.com/show/AiCp777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
有以下程序intfun(intn)main(){if(n==1)return1;{intx;Elsescanf("%d”,&x);x=fun(x);
fun函数的功能是:通过键盘输入给x所指的整型数组所有元素赋值。在下划线处应填写的是#include#defineN5Voidfun(intx[N]){intm;for(m=N-1;m>=0;
有以下程序main(){inti,j;for(i=1;i
若有以下程序main(){inta=-2,b=0;while(a++)++b;pfintf("%d,%d\n",a,b);}则程序的输出结果是
下列叙述中正确的是
下列给定程序中,函数fun的功能是:将m(1≤m≤10)个字符串连接起来,组成一个新串,放入pt所指存储区中。例如:把三个串“abe”“CD”“EF”连接起来,结果是”abc-CDEF”。请改正程序中的错误,使它能得出正确的结果。注意:不要
请编写函数voidfun(intx,intpp[],int*n),它的功能是:求出能整除x且不是偶数的各整数,并按从小到大的顺序放在pp所指的数组中,这些除数的个数通过形参n返回。例如,若x中的值为30,则有4个数符合要求,它们是1、3
下面选项中不是关系数据库基本特征的是()。
结构化程序包括的基本控制结构是
下列选项中不属于结构化程序设计原则的是
随机试题
审美现象背后体现的实质是人与世界之间的【】
男性,25岁,1周前发现肺内阴影,查痰结核菌2+,该患者适宜的治疗方案为男性,30岁,1年前发现肺结核,以INH、EMB间断治疗一年,目前治疗宜采取的方案为
突然缩小管路,缩小前后管路直径分别为200mm和100mm,缩小前断面平均流速为v1=1m/s,则局部水头损失hm为()m。
某中外合资经营企业的外方合营者未按照合同的规定如期缴付其出资,经中方合营者催告1个月后仍未缴付的,可能引起的法律后果有()。
公民道德建设是进行社会公德、职业道德和家庭美德建设的前提和条件。()
当落日沉没,周围雪峰的红光逐渐_____,银灰色的暮霭笼罩着草原的时候,你就会看见无数点的红火光。填入画横线部分最恰当的一项是()。
在五大宗教中,汉族只信仰道教和佛教。()
被视为夺冠大热门的斗牛士竟然_________瑞士零封,最终0比1输掉比赛,这无疑给了野心勃勃要完成欧洲杯冠军再夺世界杯的斗牛士们重大_________。历史资料显示,首战输球的球队还没有夺冠的经历。第二场打洪都拉斯,西班牙除了获胜别无选择,这个小组的出线
纪律转化为个体内部的要求,也即()是个体社会化的一项重要内容。
Arepasswordsoutdated?It’sstartingtoseemlikeit.Everybodyhatesthem,andnobodycanrememberalltheonesthey’ve【C1】___
最新回复
(
0
)