fork(1) download
  1. #include <stdio.h>
  2.  
  3. void swap(int* a, int *b) {
  4. int tmp = *a;
  5. *a = *b;
  6. *b = tmp;
  7. }
  8.  
  9. void print(int m[3][3]) {
  10. for (int r = 0 ; r != 3 ; r++) {
  11. for (int c = 0 ; c != 3 ; c++)
  12. printf("%d ", m[r][c]);
  13. printf("\n");
  14. }
  15. }
  16.  
  17. int main(void) {
  18. int m[3][3] = {{1,2,3}, {4, 5, 6}, {7, 8, 9}};
  19. print(m);
  20. printf("--------\n");
  21.  
  22. swap(&m[0][0], &m[2][0]);
  23. swap(&m[0][1], &m[1][0]);
  24. swap(&m[0][2], &m[2][0]);
  25. swap(&m[1][0], &m[2][1]);
  26. swap(&m[1][2], &m[2][1]);
  27. swap(&m[2][2], &m[2][0]);
  28.  
  29. print(m);
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
1 2 3 
4 5 6 
7 8 9 
--------
7 4 1 
8 5 2 
9 6 3