有以下程序 fun(intx) {intp; if(x=0‖x=1)return(3); p=x-fun(x-2); returnp; } main( ) {printf(’’%\n’’,fun(7));) 执行后的输出结果是

admin2014-06-18  15

问题 有以下程序
fun(intx)
{intp;
if(x=0‖x=1)return(3);
p=x-fun(x-2);
returnp;
}
main(    )
{printf(’’%\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://jikaoti.com/ti/gpn0FFFM
0

最新回复(0)