有以下程序: #include<stdio.h> int f(int t[],int n); main() { int a[4]={1,2,3,4},s; s=f(a,2);printf(’’%d\n’’,s);}

admin2020-07-28  22

问题 有以下程序:
    #include<stdio.h>
    int f(int t[],int n);
    main()
    { int a[4]={1,2,3,4},s;
    s=f(a,2);printf(’’%d\n’’,s);}
    int f(int t[],int n)
    {  if((n>0)&&(n<5))return t[n+1]+f(t,n-1);
    else return 0;}
    程序运行后的输出结果是(    )。

选项 A、4
B、7
C、10
D、6

答案B

解析 本题主要考查的是函数的递归调用,子函数f是一个递归函数,所以主函数中执行“f(a,2)”时,其执行过程是“a[3]+f(a,1)=a[3]+a[2]+f(a,0)=7”。
转载请注明原文地址:https://kaotiyun.com/show/hF3p777K
0

随机试题
最新回复(0)