C语言编程返回数组的前n个元素之和
#include<stdio.h> int sun(int *a,int n) { /* int i,sum = 0; for(i = 0;i < n;i++) sum += a[i]; return sum; */ static int sum = 0; if(n-- > 0) { sum += a[n]; sun(a,n); } return sum; } int main(int argc,char *argv[]) { int a[] = {1,2,3,4,5,6}; printf("%d\n",sun(a,5)); return 0; }