I think I just need a kick start on this one, because I dont know where to begin. I know what I have to do in theory, but pulling it off is another thing:

Write the function vec_to_mat (int *v, int *mat, int n); v is a pointer to the beginning of an integer array (vector) with n x n elements stored in column-major representation (see below for explanation). The function should copy the elements from v to mat (which is a matrix of size n x n). From example,

If v is {1, 2, 3, 4, 5, 6, 7, 8, 9}, the value of mat should be,

1 4 7

2 5 8

3 6 9

The values 1, 2, and 3 go down the first column of matrix mat, and then 4, 5, 6 goes down the second column and so on.

I have written this much so far:

I know it isn't much, but I dont know where to begin on the copying of the values from *v into a matrix like that without doing it element by element.Code:#include <stdio.h> #include <stdlib.h> int vec_to_mat (int *v, int *mat, int n){ int a; for(a=0, a<n, a++){ } } int main() { int a [] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; int matrix [3][3]; vec_to_mat (a, matrix[0], 3); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { printf ("%d", matrix [i][j]); } printf ("\n"); } system("PAUSE"); }