问题
单项选择题
有以下程序:
#include <stdio.h>
int f(int t[],int n);
main()
int a[4]=1,2,3,4,s;
s=f(a,4);printf("%d\n",s);
int f(int t[] ,int n)
if(n>0) return t[n-1]+f(t,n-1);
else return 0;
程序运行后的输出结果是
A) 4
B) 10
C) 14
D) 6
答案
参考答案:B
解析: 函数的功能是求数组所有元素的和。递归表示为a[3]+a[2]+a[1]+a[0]+f(t,0)=10。