fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int cols,rows;
  6. cin >> cols >> rows;
  7. int a[cols][rows];
  8. int b[rows][cols];
  9. for(int i = 0; i<cols; i++){
  10. for(int j = 0; j<rows; j++){
  11. cin >> a[i][j];
  12.  
  13. }
  14. }
  15. for(int i = 0; i<rows; i++){
  16. for(int j = 0 ; j<cols; j++){
  17. b[i][j] = a[j][i];
  18. }
  19. }
  20. for(int i = 0; i<rows; i++){
  21. for(int j = 0; j<cols; j++){
  22. cout << b[i][j] << " ";
  23. }
  24. cout << endl;
  25. }
  26. return 0;
  27. }
Success #stdin #stdout 0s 4172KB
stdin
3 2
1 2
3 4
5 6
stdout
1 3 5 
2 4 6