SUM_2D.C
上传用户:qq5388545
上传日期:2022-07-04
资源大小:29849k
文件大小:1k
- #include <stdio.h>
- long sum_array(int array[], int elements)
- {
- long sum = 0;
- int i;
- for (i = 0; i < elements; i++)
- sum += array[i];
- return(sum);
- }
- void main(void)
- {
- int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
- int b[2][10] = {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
- {11, 12, 13, 14, 15, 16, 17, 18, 19, 20}};
- int c[3][10] = {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
- {11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
- {21, 22, 23, 24, 25, 26, 27, 28, 29, 30}};
- printf("Sum of first array elements %dn", sum_array(a, 10));
- printf("Sum of second array elements %dn", sum_array(b, 20));
- printf("Sum of third array elements %dn", sum_array(c, 30));
- }