Technically, the clean way to copy the elements of a 1d array a to a NxM matrix m would be a nested loop over the rows and columns of the matrix:
int arrayIndex = 0;
for (int row = 0; row < N; ++row) {
for (int column = 0; column < M; ++column) {
m[row][column] = a[arrayIndex];
++arrayIndex;
}
}
As you can see, you not only need a double loop to iterate over the elements of the 2D matrix, you also need to maintain the index to the 1d array that you are copying from.
There are simpler solutions, but for now I suggest implementing this in your code and make sure it produces the desired results.