求二維數組周邊元素之和?
#include
using namespace std;
int add(int* a, int n, int m) {
int i,j;
int sum = 0;
for (i = 0; i
if (i == 0 || i == n-1) {
for ( j = 0; j
sum += a[i*m+j];
}
}
else {
sum += a[i*m];
sum += a[i*m+m-1];
}
return sum;
}
int main() {
int a[4][5];
int i,j,n;
n = 0;
for (i = 0; i
for (j = 0; j
a[i][j] = n;
cout
}
cout
}
cout
return 0;
}