问题
单项选择题
以下程序运行后的输出结果是
#include <stdio.h>
int fun(int a,int b)
if(b==0) return a;
else return(fun(--a,--b));
main( )
printf("%d\n",fun(4,2));
A.1
B.2
C.3
D.4
答案
参考答案:B
解析: 该题为递归调用程序。调用f(4,2),保留操作return(fun(3,1));,调用f(3,1),保留操作return(fun(2,0));,调用f(2,0),返回2。再倒推回去,f(4,2)返回结果为2。