Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <inttypes.h>
- #include <stdlib.h>
- /*
- * Given a matrix, transpose it. Transposing a matrix means the rows are now the column and vice-versa.
- * Here's an example:
- * input = [[1, 2, 3],
- * [4, 5, 6]]
- * output = [[1, 4],
- * [2, 5],
- * [3, 6]]
- */
- int* transpose(const int* in_mat, const uint32_t rows, const uint32_t cols) {
- // TODO: implement
- return NULL;
- }
- int main() {
- const int rows = 2;
- const int cols = 3;
- const int in_mat[rows][cols] = {{1, 2, 3},
- {4, 5, 6}};
- int* result = transpose(&in_mat[0][0], rows, cols);
- for (int i=0; i<cols; ++i) {
- for (int j=0; j<rows; ++j) {
- printf("%d ", result[i*cols + j]);
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement