问题
单项选择题
有以下程序
#include<stdio.h>
int fun(int a,int b)
if(b==0) retum a;
else return(fun(--a,--b));
main()
printf("%d\n",fun(4,2));
程序的运行结果是()。
A.1
B.2
C.3
D.4
答案
参考答案:B
解析:
由程序可知,函数fun(int a,int b)是一个递归函数。所以当主函数中调用fun(4,2)时,其执行过程如下:fun(4,2)->fun(3,1)->fun(2,0),其返回值为2。所以正确答案为选项B。