给定如下函数(函数功能同上题,增加输出打印): 则当 时,屏幕上输出序列为( )。
int fun(int n) {
cout << n << " ";
if (n == 1) return 1;
if (n == 2) return 2;
return fun(n - 2) - fun(n - 1);
}
- A. 4 3 2 1
- B. 1 2 3 4
- C. 4 2 3 1 2
- D. 4 2 3 2 1
正确答案:C
int fun(int n) {
cout << n << " ";
if (n == 1) return 1;
if (n == 2) return 2;
return fun(n - 2) - fun(n - 1);
}
正确答案:C
想系统刷完 GESP C++ 1~8 级真题,并查看每道题的逐题精讲?
进入 GESPPASS 开始练习