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;
}

posted @ 2020-01-16 11:16  PCDL&TIPO  阅读(3880)  评论(0编辑  收藏  举报