单选题 C++
题号 #2251372

以下程序的输出结果是(  )。
#include<iostream.h>
longfun(intn)
{longs;
if(n=-1‖n==2)s=2;
elses=n-fun(n-l):
returns;
}
voidmain(  ){cout<<fun(3);}

进入在线模考

参考答案

A

答案解析

A。【解析】题中fun函数进行了递归调用,第1次调用时:fun(3)n=3,s=3-fun(2),第二次调用时:fun(2)n=2,s=2,返回第一次调用后,s=3-2=1。

你可能感兴趣的试题

找试题 · 找答案 · 找资料 在线模考