首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有以下程序 fun(int x) {int p; if(x==0 ‖ x==1)return(3); p=x-fun(x-2); return p; } main() { printf("%d
有以下程序 fun(int x) {int p; if(x==0 ‖ x==1)return(3); p=x-fun(x-2); return p; } main() { printf("%d
admin
2016-12-28
64
问题
有以下程序
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(intx)中,如果参数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/grDp777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
有以下程序:#include<stdio.h>main(){FILE*fp;inti,a[6]={1,2,3,4,5,6};fp=fopen("d2.dat","w");fprintf(fp,"%d%d%d\n"
若a是int型变量,且a的初值为4,则计算a+=a-=a*a表达式后a的值为______。
定义下列结构体(联合)数组:structSt{charname[15];intage;}a[10]={"ZHAO",14,"WANG",15,"LIU",16,"ZHANG",17};执行语句prin
下列程序的输出结果是()。#include<stdio.h>voidmain(){inta=0,b=1,c=2;if(++a>0‖++b>0)++C;printf("%d,%d,%d",a,b
执行语句printf("%u\n",+12345)的输出结果是()。
下列关于栈的描述中错误的是()。
在数据库设计中,将E-R图转换为关系模式的过程属于()。
有以下程序段,且变量已正确定义和赋值for(s=1.0,k=1;k<=n;k++)s=s+1.0/(k*(k+1));printf("s=%f\n\n",s);请填空,使下面程序段的功能与之完全相同S=1.0;k=1;while([8]
设有定义:inta=2,b=3,c=4;,则下列选项中值为0的表达式是()。
随机试题
极度衰弱患者的体位是()
Heisn’tsuchaman_____heusedtobe.
小儿头围与胸围两者几乎相等的年龄足
在收集评价资料的过程中,调查员使用了诱导性提高,属于影响评价因素中的
一级房地产评估机构应具备的条件为()。土地增值税的计税依据是()。
在组织结构的内容体系中,职权结构指的是()。
In1924America’sNationalResearchCouncilsenttwoengineerstosuperviseaseriesofexperimentsatatelephone-partsfactory
PeopleallovertheworldknowWimbledonasthecentreoflawntennis. In1874itwasacountryvillage,butitwasthehome
Inspiring,chicandeffortlesslyelegant—that’swhatdesignersatLondonFashionWeekhailedKateMiddleton’sstyle,ashersa
ThenumberofspeakersofEnglishinShakespeare’stimeisestimatedtohavebeenaboutfivemillion.Todayitisestimatedthat
最新回复
(
0
)