Advertisement
mxn12

Cau2_XoayMang2Chieu

Feb 17th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void rotate(int arr[][3], int n)
  5. {
  6. int tmp[3][3];
  7. for (int i = 0; i < n; i++) {
  8. for (int j = 0; j < n; j++) {
  9. tmp[j][n - 1 - i] = arr[i][j];
  10. }
  11. }
  12.  
  13. for (int i = 0; i < n; i++) {
  14. for (int j = 0; j < n; j++) {
  15. cout << tmp[i][j] << " ";
  16. }
  17. cout << endl;
  18. }
  19. }
  20.  
  21. int main() {
  22. int arr[3][3] = { {1,2,3},{4,5,6},{7,8,9} };
  23.  
  24. rotate(arr, 3);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement