split 2d array into chunks in c 2b 2b

Solutions on MaxInterview for split 2d array into chunks in c 2b 2b by the best coders in the world

showing results for - "split 2d array into chunks in c 2b 2b"
Holly
28 Jul 2018
1int main(int agrc, char *argv[])
2{
3    const size_t w = 8;
4    const size_t h = 3;
5    const size_t c = 2;
6
7    int mat[h][w] = {
8        { 1, 2, 3, 4, 5, 6, 7, 8 },
9        { 1, 2, 3, 4, 5, 6, 7, 8 },
10        { 1, 2, 3, 4, 5, 6, 7, 8 }
11    };
12
13    int chunks[w / c][h][c];
14
15    split(h, w, mat, c, chunks);
16
17    for (int i = 0; i < w / c; i++) {
18        for (int j = 0; j < h; j++) {
19            for (int k = 0; k < c; k++) {
20                printf("%3d ", chunks[i][j][k]);
21            }
22            printf("\n");
23        }
24        printf("\n\n");
25    }
26
27    return 0;
28}