# Transpose Matrix

This algorithm finds the transpose of a given matrix. The transpose of a given matrix is formed by interchanging the rows and columns of a matrix.

```									```/*****Please include following header files*****/
// stdlib.h
/***********************************************/

typedef struct {
int** Matrix;
int Rows;
int Columns;
} Matrix;

int** CreateMatrix(int rowCount, int colCount) {
int** matrix = (int**)malloc(sizeof(int*) * rowCount);

for (int i = 0; i < rowCount; ++i) {
matrix[i] = (int*)malloc(sizeof(int) * colCount);
}

return matrix;
}

Matrix TransposeMatrix(Matrix matrix) {
int** transpose = CreateMatrix(matrix.Columns, matrix.Rows);

for (int i = 0; i < matrix.Rows; ++i)
for (int j = 0; j < matrix.Columns; ++j)
transpose[j][i] = matrix.Matrix[i][j];

return{ transpose, matrix.Columns, matrix.Rows };
}```
```

### Example

```									```int** m1 = CreateMatrix(2, 3);
m1 = 1;
m1 = 2;
m1 = 3;
m1 = 4;
m1 = 5;
m1 = 6;

Matrix matrix = { m1, 2, 3 };
Matrix transpose = TransposeMatrix(matrix);```
```

### Output

```									``` = 1
 = 4
 = 2
 = 5
 = 3
 = 6```
```