计算数组里所有数的和

#include "stdio.h"
#include "windows.h"
int a[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
sum(int a[],int n)
{
if(n<=0)
return 0;
return a[n-1]+sum(a,n-1);
}
main()
{
int i;
system("cls");
printf("\n the arry is:\n");
for (i=0;i {
printf("%d",a[i]);
}
printf("\n sum of the arry is: %d\n",sum(a,sizeof(a)/sizeof(a[0])));
printf("\n press any key to quit ...\n");
getchar();
}

你可能感兴趣的:(计算数组里所有数的和)