单循环+双指针
以线性模式遍历2维数组
取和 Sample:
#include <stdio.h>
#define LEN 10
int sum_two_dimensional_array(int a[][LEN], int n){
int *p1 = *a, *p2 = *a;
int sum = 0;
for (; p1 <= p2 + 19; p1++) {
sum += *p1;
}
return sum;
}
int main(){
int numbers[2][LEN] = {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}};
printf("The sum of all elements of the array is: %d\n",
sum_two_dimensional_array(numbers, 2));
return 0;
}