#include "stdlib.h"
int sum (int *,int);
int main()
{
int i[]={10,20,30,40,50};
int total;
total = sum (i ,sizeof(i)/sizeof(i[0]));
printf("Sum of Array i is %d\r\n",total);
return 0;
}
int sum(int *p,int n)
{
int k,total=0;
for(k=0; k < n; k++)
total +=*(p+k);
return total;
}
=====Result=====
Sum of Array i is 150
沒有留言:
張貼留言