fork download
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5. int a[4][4] ;
  6.  
  7. std::cout << "enter array\n" ;
  8. for( int row = 0 ; row<4 ; ++row )
  9. for( int col = 0 ; col < 4 ; ++col )
  10. std::cin >> a[row][col] ;
  11.  
  12. int b[16] ;
  13. int pos = 0 ;
  14. for( int row = 0 ; row<4 ; ++row )
  15. for( int col = 0 ; col < 4 ; ++col )
  16. b[pos++] = a[col][row] ;
  17.  
  18. for( int k = 0 ; k < 16 ; ++k ) std::cout << b[k] << ' ' ;
  19. std::cout << '\n' ;
  20. }
  21.  
Success #stdin #stdout 0s 2856KB
stdin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
stdout
enter array
1 5 9 13 2 6 10 14 3 7 11 15 4 8 12 16