c语言数组求和
数组求和
#include<stdio.h>
#include<stdlib.h>
int fun(int a[], int len)
{
int i,sum=0;
if (len == 0)
{
return 0;
}
else{
for (i = 0; i < len; i++)
{
sum += a[i];
}
return sum;
}
}
int main()
{
int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int len = sizeof(a) / sizeof(a[0]);
int sum;
sum=fun(a, len);
printf("%d", sum);
system("pause");
return 0;
}