首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有以下程序: #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
2019-08-18
16
问题
有以下程序:
#include
int fun(int x)
{
int P;
if(x==0‖x==1)
return(3);
P=x—fun(x一2);
return p;
}
main()
{
prinff(“%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/eZRp777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
函数fun的功能是:把形参a所指数组中的偶数按原顺序依次存放到a[0]、a[1]、a[2]、……中,把奇数从数组中删除,偶数个数通过函数值返回。例如:若a所指数组中的数据最初排列为:9、1、4、2、3、6、5、8、7,删除奇数后a所指数组中的数据
给定程序中,函数fun的功能是:找出100~999之间(含100和999)所有整数中各位上数字之和为x(x为一正整数)的整数,然后输出;符合条件的整数个数作为函数值返回。例如,当x值为5时,100~999之间各位上数字之和为5的整数有:104、
学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组S中,请编写函数fun,它的功能是:把分数最高的学生数据放在h所指的数组中,注意:分数最高的学生可能不止一个,函数返回分数最高的学生的人数。注意:部分源程序在文件PROG1.C中
函数fun的功能是:把形参a所指数组中的奇数按原顺序依次存放到a[0]、a[1]、a[2]、……中,把偶数从数组中删除,奇数个数通过函数值返回。例如:若a所指数组中的数据最初排列为:9、1、4、2、3、6、5、8、7,删除偶数后a所指数组中的数据
给定程序MODI1.C中函数fun的功能是:按顺序给s所指数组中的元素赋予从2开始的偶数,然后再按顺序对每五个元素求一个平均值,并将这些值依次存放在W所指的数组中。若S所指数组中元素的个数不是5的倍数,多余部分忽略不计。例如,S所指数组有14个元
请编写函数fun,函数的功能是:统计各年龄段的人数。N个年龄通过调用随机函数获得,并放在主函数的age数组中;要求函数把0至9岁年龄段的人数放在d[0]中,把10至19岁年龄段的人数放在d[1]中,把20至29岁年龄段的人数放在d[2]中,其余依此类推,
给定程序中,函数fun的功能是将带头结点的单向链表逆置。即若原链表中从头至尾结点数据域依次为:2、4、6、8、10,逆置后,从头至尾结点数据域依次为:10、8、6、4、2。请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
请编写函数fun,其功能是:将一个数字字符串转换为一个整数(不得调用C语言提供的将字符串转换为整数的函数)。例如,若输入字符串“一1234”,则函数把它转换为整数值一1234。注意:部分源程序给出如下。请勿改动主函数main和其他函数中
下列给定程序中,函数fun的功能是:将形参n所指变量中,各位上为偶数的数去掉,剩余的数按原来从高位到低位的顺序组成一个新数,并通过形参指针n传回所指变量。例如,若输入一个数27638496,则新数为739。请在程序的下画线处填入正确的内容并将下
随机试题
当桥梁主塔(墩)塔身高于()m时,应在其顶端装设防撞信号灯。
他律性
根据《物权法》的规定,按份共有人转让其共有财产时,其他共有人在同等条件下有()
选择性α2受体阻断药是
土地登记权属审核的应达标准不包括()。
建设项目管理的工作内容包括项目策划和(。)。
根据《招标投标法实施条例》,对于应当公开招标的施工招标项目可以进行邀请招标的是()。
杜邦分析体系的核心指标是()。
Mycorrhizalfungiinfectmoreplantsthandoanyotherfungiandarenecessaryformanyplantstothrive,buttheyhaveescaped
HitlerandhismenhadtheirhatredtowardsJewsandcolorpeople.Oursocietyisriddledwithsuchhatredbased【S1】_
最新回复
(
0
)