Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <inttypes.h>
  3. #include <stdlib.h>
  4.  
  5. /*
  6. * Given a matrix, transpose it. Transposing a matrix means the rows are now the column and vice-versa.
  7. * Here's an example:
  8. * input = [[1, 2, 3],
  9. * [4, 5, 6]]
  10. * output = [[1, 4],
  11. * [2, 5],
  12. * [3, 6]]
  13. */
  14.  
  15. int* transpose(const int* in_mat, const uint32_t rows, const uint32_t cols) {
  16. // TODO: implement
  17. return NULL;
  18. }
  19.  
  20. int main() {
  21. const int rows = 2;
  22. const int cols = 3;
  23. const int in_mat[rows][cols] = {{1, 2, 3},
  24. {4, 5, 6}};
  25.  
  26. int* result = transpose(&in_mat[0][0], rows, cols);
  27.  
  28. for (int i=0; i<cols; ++i) {
  29. for (int j=0; j<rows; ++j) {
  30. printf("%d ", result[i*cols + j]);
  31. }
  32. printf("\n");
  33. }
  34.  
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement