首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
下列程序的输出结果为 #include<iostream.h> int func(int n) { if(n<1) return 1; else retur n+func(n-1) ; return
下列程序的输出结果为 #include<iostream.h> int func(int n) { if(n<1) return 1; else retur n+func(n-1) ; return
admin
2010-12-16
22
问题
下列程序的输出结果为
#include<iostream.h>
int func(int n)
{
if(n<1) return 1;
else retur n+func(n-1) ;
return 0;
}
void main( )
{
cout < < func(5) < < endl;
}
选项
A、0
B、10
C、15
D、16
答案
D
解析
本题考查的是递归函数的使用,题中递归函数的结束条件为n<1,递推公式为f(n) =n +f(n-1) ,所以计算结果为5+4+3+2+1+1,最后一个1为n=0时的返回值。
转载请注明原文地址:https://jikaoti.com/ti/bqL0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下程序:#include<stdio.h>main(){intx[3][3]={1,2,3,4,5,6,7,8,9},i;for(i=1;i<3;i++)printf("%d
学生选课成绩表的关系模式是SC(S#,C#,G),其中S#为学号,C#为课号,G为成绩,检索课号为2且成绩及格的学生学号的表达式为
有以下程序:#include<stdio.h>#include<string.h>typedefstruct{charname[9];charsex;floatscore[2];}STU;voidf(STUa){STUb={"Zh
设有两行定义语句:intscanf;floatcase;则以下叙述正确的是()。
设有如下语句:typedefstreetDate{intyear;intmonth;Intday:}DATE;则以下叙述中错误的是()。
计算机软件通常分为应用软件、系统软件和支撑软件(或工具软件)。下面属于应用软件的是()。
设循环队列为Q(1:m),其初始状态为front=rear=m。经过一系列入队与退队运算后,front=20,rear=15。现要在该循环队列中寻找最小值的元素,最坏情况下需要比较的次数为()。
if语句的基本形式为:if(表达式)语句,其中“表达式”()。
由以下while构成的循环,循环体执行的次数是()。intk=0;while(k=1)k++;
面向对象方法中,继承是指()。
随机试题
关于自身免疫病的一般特点,不正确的是
A、脾切除B、干扰素C、异基因骨髓移植D、免疫抑制剂E、VDP方案CML的治疗可选择
当采用钢木檀条或胶合木檀条时,桁架间距不宜大于()
建设工程物资采购合同纠纷有( )。
通常情况下,与非累积带薪缺勤相关的职工薪酬已经包括在企业每期向职工发放的工资等薪酬中,因此不必额外作相应的账务处理。()
用户及其应用程序和应用系统是通过()提供的支持和服务来使系统资源完成其作用。
一般资料:求助者,男性,16岁,高中一年级学生。案例介绍:求助者从小有咬指甲的习惯,多次受到父母的训斥。自己也很想改,但做了很多努力,没有明显效果,主动前来寻求帮助。下面是心理咨询师与该求助者之间的一段咨询对话:心理咨询师:通
对于各种特殊学生,在教学中贯彻因材施教原则,要做到()
右图所示的窗体上有一个命令按钮(名称为Commandl)和一个选项组(名称为Framel),选项组上显示“Framel”文本的标签控件名称为LaBel,若将选项组上显示文本“Framel”改为汉字“性别”,应使用的语句是【】。图
Ifourbrainswerecomputers,we’dsimplyaddachiptoupgradeourmemory.Thehumanbrain,therefore,ismore【M1】______comple
最新回复
(
0
)