Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void swap(int a[][3], int b[][3], int r, int c);
  6.  
  7. int main()
  8. {
  9. int a[3][3] = {
  10. {0, 1, 2},
  11. {3, 4, 5},
  12. {6, 7, 8}
  13. };
  14.  
  15. int b[3][3] = {
  16. {20, 21, 22},
  17. {23, 24, 25},
  18. {26, 27, 28}
  19. };
  20.  
  21. for (int r = 0; r < 3; r++)
  22. {
  23. for (int c = 0; c < 3; c++)
  24. {
  25. if (r == c)
  26. {
  27. swap(a, b, r, c);
  28. }
  29. }
  30. }
  31.  
  32. cout << a[0][0];
  33. }
  34.  
  35. void swap(int &a, int &b, int r, int c)
  36. {
  37. int temp = a;
  38. b[r][c] = a;
  39. a[r][c] = temp;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement