fork download
  1. #include<stdio.h>
  2. #define ROW 4
  3. #define COL 4
  4. int M[ROW][COL] = {{1, 2, 3, 4}, {5, 6, 7, 8},{ 9, 10, 11, 12}, {13, 14, 15, 16}};
  5. int main()
  6. {
  7. int i, j, t;
  8. for (i = 0; i < 4; ++i)
  9. {
  10. for(j = 0; j < 4; ++j){
  11. t = M[j][i];
  12. M[i][j] = M[j][i];
  13. M[j][i] = t;
  14. }
  15. }
  16. for (i = 0; i < 4; ++i)
  17. {
  18. for (j = 0; j < 4; ++j)
  19. printf ("%d ", M[i][j]);
  20. printf ("\n");
  21. }
  22. }
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
1 5 9 13 
5 6 10 14 
9 10 11 15 
13 14 15 16