fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #define row_size 4
  5.  
  6. void print_matrix(int matrix[][row_size], int col_size)
  7. {
  8. for(int i = 0; i < col_size; i++) {
  9. for(int j = 0; j < row_size; j++) {
  10. cout << matrix[i][j] << " ";
  11. }
  12. cout << endl;
  13. }
  14. }
  15.  
  16. int main() {
  17. // your code goes here
  18. int data[][row_size] = { {1,2,3,4}, {5,6,7,8}, {9,10,11,12} };
  19. int col_size = sizeof(data) / sizeof(data[0]);
  20. print_matrix(data, col_size);
  21.  
  22. int index_shift = row_size / 2 + row_size % 2;
  23.  
  24. for(int i = 0; i < col_size; i++)
  25. {
  26. for(int j = 0; j < row_size/2; j++)
  27. {
  28. int swap = data[i][j];
  29. data[i][j] = data[i][ index_shift + j];
  30. data[i][index_shift + j] = swap;
  31. }
  32. }
  33. cout << "--------------" << endl;
  34. print_matrix(data, col_size);
  35. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
1 2 3 4 
5 6 7 8 
9 10 11 12 
--------------
3 4 1 2 
7 8 5 6 
11 12 9 10