单选题
C++
题号 #2607468
下列程序的输出结果为( )。
#include<iostream.h) int fune(int n)
{
if(n<1)return l;
else return n+time(n一1); return 0;
}
void main() {
cout<<func(5)<<endl;
}
参考答案
D
答案解析
本题考查的是递归函数的使用,题中递归函数的结束条件为n<J,递推公式为f(n)=n+f(n—1),所以计算结果为5+4+3+2+】+1,最后一个】为n=0时的返回值。
你可能感兴趣的试题
A.⑤
B.⑥
C.⑦
D.⑪
A.(operator++(x)).operator/(Y)
B.(operator++(0)).operator/(Y)
C.operator/((operator++(x,0)),Y)
D.operator/((operator++(0)),Y)