1. ## column-major matrix Q....

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:

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");
}```
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.

2. Code:
```int vec_to_mat(int *v, int *mat, int n)
{
int x, y;

for(y = 0; y < n; y++)
for(x = 0; x < n; x++)
mat[x + n * y] = v[y + n * x];
}```
Note how the roles of x and y are swapped in the last line. Just treat the 2D arrays like 1D arrays for stuff like this, since they are both fundamentally the same. If you want to be slick, you can incorporate the printf into the same loop. Hope that helps.

-Joe

3. Thank you for the response, although in many ways that was more than I needed. I cant complain though. I changed some stuff around to fit into pointer notation. The final source looks like this:

Code:
```#include <stdio.h>
#include <stdlib.h>

int vec_to_mat(int *v, int *mat, int n)
{
int x, y;

for(y = 0; y < n; y++)
for(x = 0; x < n; x++)
*(mat + (x + n * y)) = *(v + (y + n * x));
}

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");
}```

4. It probably can be done with one loop, but the basic idea was easier to show with two. The multiplies would be slow for a large array, maybe try a version without them? Stuff to try...

-Joe