首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有以下程序 fun(int x) { int p; if(x==0‖x==1)return(3); p=x-fun(x-2); return p; } main() { pri
有以下程序 fun(int x) { int p; if(x==0‖x==1)return(3); p=x-fun(x-2); return p; } main() { pri
admin
2019-12-17
21
问题
有以下程序
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、3
B、7
C、0
D、2
答案
D
解析
因为在函数fun(int x)中,如果参数x等于0或1时,返回值3。否则p=x-fun(x-2)这是一个递归函数,所以在主函数调用fun(7)时,其过程为:“fun(7)=7-fun(5)=7-(5-fun(3))=7-(5-(3-fun(1)))=7-(5-(3-3))=7-5=2”,所以最后的输出结果为2。
转载请注明原文地址:https://kaotiyun.com/show/t2Cp777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
有以下程序#include<stdio.h>voidf(int*p,int*q)voidf(int*p,int*q);{main()p=p+1;*q=*q+1;{intm=1,n=2,*r=&m;}f(r,&n);print
有以下程序,程序的输出结果是main(){intsum,pad,pAd;sum=pad=5;pAd=++sum,pAd++,++pad;printf("%d\n",pad);}
有如下嵌套的if语句if(a<b)iffa<c)k=a;elsek=c:elseif(b<c)k=b;elsek=c;以下选项中与上述if语句等价的语句是
设变量已正确定义,以下不能统计出一行中输入字符个数(不包含回车符)0的程序段是
下列数据结构中,能够按照“先进后出”原则存取数据的是
下列叙述中正确的是
以下叙述中正确的是
数据库管理系统是
若有定义typedefcharT[10];T*a;上述定义中a的类型与下面选项中完全相同的是
请编写函数fun,其功能是:将M行N列的二维数组中的字符数据,按列的顺序依次放到一个字符串中。例如,若二维数组中的数据为WWWWSSSSHHHH则字符串中的内容应是:WSHWSHWSHWSH。
随机试题
依据《金属非金属矿山安全规程》,有人员作业场所的井下气象条件符合要求的是()。
确定划线基准应遵循哪几个原则?
试述“一个中心”和“两个基本点”之间的关系。
More______,lessspeed.
298K时,反应A(g)+B(g)=2C(g)+D(g)的KΘ=2,若A、B、C、D的起始压分别为100kPa、200kPa、33.5kPa、67kPa,则298K时反应()。
促销的实质是()。
1926年美国出售的汽车约70%是用分期付款的形式进行,当时美国流行的说法是:“一美元首付,一美元月供”。这种现象造成的影响是()。
Skopostheory
ThismuseumisoneoftheoldestinstitutionsintheUnitedStatesdedicatedto______thenation’srailroadhistory.
Bloggingisapastimeformany,evenalivelihoodforafew.Forsome,itbecomesan【36】Suchbloggersoftenfeelcompelledtowr
最新回复
(
0
)