#include #include #define MAXR 10 #define MAXC 10 int buildMatrix(int V[], int N, int M[MAXR][MAXC], int nr, int nc) { int p = 0, x, y; if (N % 2 == 1) { return 1; } for (int i = 0; i < N; i += 2) { for (int j = 0; j < (V[i+1]); j++) { x = p / nc; y = p % nc; if (x >= nr) { return 1; } if (y == 0) { putchar('\n'); } M[x][y] = V[i]; printf("%d\t", V[i]); p++; } } putchar('\n'); p--; if (p / nc != (nr - 1) || p % nc != (nc - 1)) { return 1; } return 0; } int main(){ int arr[MAXR][MAXC]; int vec[] = {1, 2, 17, 2, 3, 1, 8, 4, 6, 1, 7, 3, 5, 2}; printf("%d", buildMatrix(vec, 14, arr, 3, 5)); return 0; }