1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// tiny sample code for malloc 2D array

int m, n; //給出你的矩陣m*n大小 
int size = m*n; 
int *my2DArray = (int*)malloc(size*sizeof(int));
for (int x=0; x<m; x++) {
  for (int y=0; y<n; y++) {
    my2DArray[x+y*m] = 0;
  }
}

//取出column yy
for (int z=0; z<size; z++) {
  if (z%m == yy) {
    //do sth to my2DArray[z]
  }
}

//取出row xx
for (int z=0; z<size; z++) {
  if (z/n == xx) {
    //do sth to my2DArray[z]
  }
}