Rotate a matrix by 90 degree in clockwise direction without using any extra space in C++

We are given a 2-D array that will be used to form a matrix pattern. The task is to rotate a matrix by 90 degrees in a clockwise direction such that the last row becomes the first column, second row becomes second column and first becomes third column and the challenge is that we don’t
have to use any extra space.
Input −
int arr[row_col_size][row_col_size] = { { 5, 1, 4},
   { 9, 16, 12 },
   { 2, 8, 9}}
Output −
Rotation of a matrix by 90 degree in clockwise direction without using any extra space is:
2 9 5
8 16 1
9 12 4
Explanation − we are given a 2-D array of integer type. Now we will rotate a matrix by 90 degrees in a clockwise direction.
Before rotation-:
{ { 5, 1, 4},
{ 9, 16, 12 },
{ 2, 8, 9}}
After rotation-:
2 9 5
8 16 1
9 12 4
Input   −
int arr[row_col_size][row_col_size] = { { 2, 1, 9},
   { 11, 6, 32 },
   { 3, 7, 5}}
Output   −
Rotation of a matrix by 90 degree in clockwise direction without using any extra space is:
2 9 5
8 16 1
9 12 4
Explanation − we are given a 2-D array of integer type. Now we will rotate a matrix by 90 degrees in a clockwise direction.
Before rotation-:
{ { 2, 1, 9},
{ 11, 6, 32 },
{ 3, 7, 5}}
After rotation-:
3 11 2
7 6 1
5 32 9
Input a 2-D integer array that will be treated as a matrix with row_col_size.
Input a 2-D integer array that will be treated as a matrix with row_col_size.
Pass the data to the function Rotate_ClockWise(arr).
Pass the data to the function Rotate_ClockWise(arr).
Inside the function Rotate_ClockWise(arr)Start loop FOR from i to 0 till i less than row_col_size/2.Inside the loop, start another loop FOR from j to 0 till j less than row_col_size - i - 1.Inside the loop, set ptr to arr[i][j], arr[i][j] to arr[row_col_size - 1 - j][i], arr[row_col_size - 1 - j][i] to arr[row_col_size - 1 - i][row_col_size - 1 - j], arr[row_col_size - 1 - i][row_col_size - 1 - j] to arr[j][row_col_size - 1 - i] and arr[j][row_col_size - 1 - i] to ptr.
Inside the function Rotate_ClockWise(arr)
Start loop FOR from i to 0 till i less than row_col_size/2.
Start loop FOR from i to 0 till i less than row_col_size/2.
Inside the loop, start another loop FOR from j to 0 till j less than row_col_size - i - 1.
Inside the loop, start another loop FOR from j to 0 till j less than row_col_size - i - 1.
Inside the loop, set ptr to arr[i][j], arr[i][j] to arr[row_col_size - 1 - j][i], arr[row_col_size - 1 - j][i] to arr[row_col_size - 1 - i][row_col_size - 1 - j], arr[row_col_size - 1 - i][row_col_size - 1 - j] to arr[j][row_col_size - 1 - i] and arr[j][row_col_size - 1 - i] to ptr.
Inside the loop, set ptr to arr[i][j], arr[i][j] to arr[row_col_size - 1 - j][i], arr[row_col_size - 1 - j][i] to arr[row_col_size - 1 - i][row_col_size - 1 - j], arr[row_col_size - 1 - i][row_col_size - 1 - j] to arr[j][row_col_size - 1 - i] and arr[j][row_col_size - 1 - i] to ptr.
Start loop FOR from i to 0 till i less than row_col_size. Inside the loop, start another loop FOR from j to 0 till j less than row_col_size; j++ and print arr[i][j].
Start loop FOR from i to 0 till i less than row_col_size. Inside the loop, start another loop FOR from j to 0 till j less than row_col_size; j++ and print arr[i][j].
Input a 2-D integer array that will be treated as a matrix with row_col_size.
Input a 2-D integer array that will be treated as a matrix with row_col_size.
Pass the data to the function Rotate_ClockWise(arr).
Pass the data to the function Rotate_ClockWise(arr).
Inside the function Rotate_ClockWise(arr)Start loop FOR from i to 0 till i less than row_col_size.Inside the loop, start another loop FOR from j to 0 till j less than row_col_size - i.Inside the loop, set ptr to arr[i][j], arr[i][j] to arr[row_col_size - 1 - j]arr[row_col_size - 1 - i] and [row_col_size - 1 - j] to arr[j][row_col_size - 1 - i] to ptr.Start loop FOR from i to 0 till i less than row_col_size / 2. Inside the loop, start another loop FOR from j to 0 till j less than row_col_size. Inside the loop, set ptr to arr[i][j], arr[i][j] to arr[row_col_size - 1 - i][j] and arr[row_col_size - 1 - i][j] to ptr
Inside the function Rotate_ClockWise(arr)
Start loop FOR from i to 0 till i less than row_col_size.
Start loop FOR from i to 0 till i less than row_col_size.
Inside the loop, start another loop FOR from j to 0 till j less than row_col_size - i.
Inside the loop, start another loop FOR from j to 0 till j less than row_col_size - i.
Inside the loop, set ptr to arr[i][j], arr[i][j] to arr[row_col_size - 1 - j]arr[row_col_size - 1 - i] and [row_col_size - 1 - j] to arr[j][row_col_size - 1 - i] to ptr.
Inside the loop, set ptr to arr[i][j], arr[i][j] to arr[row_col_size - 1 - j]arr[row_col_size - 1 - i] and [row_col_size - 1 - j] to arr[j][row_col_size - 1 - i] to ptr.
Start loop FOR from i to 0 till i less than row_col_size / 2. Inside the loop, start another loop FOR from j to 0 till j less than row_col_size. Inside the loop, set ptr to arr[i][j], arr[i][j] to arr[row_col_size - 1 - i][j] and arr[row_col_size - 1 - i][j] to ptr
Start loop FOR from i to 0 till i less than row_col_size / 2. Inside the loop, start another loop FOR from j to 0 till j less than row_col_size. Inside the loop, set ptr to arr[i][j], arr[i][j] to arr[row_col_size - 1 - i][j] and arr[row_col_size - 1 - i][j] to ptr
Start loop FOR from i to 0 till i less than row_col_size. Inside the loop, start another loop FOR from j to 0 till j less than row_col_size; j++ and print arr[i][j].
Start loop FOR from i to 0 till i less than row_col_size. Inside the loop, start another loop FOR from j to 0 till j less than row_col_size; j++ and print arr[i][j].
#include <bits/stdc++.h>
using namespace std;
#define row_col_size 3
void Rotate_ClockWise(int arr[row_col_size][row_col_size]){
    for(int i = 0; i < row_col_size / 2; i++){
      for(int j = i; j < row_col_size - i - 1; j++){
         int ptr = arr[i][j];
         arr[i][j] = arr[row_col_size - 1 - j][i];
         arr[row_col_size - 1 - j][i] = arr[row_col_size - 1 - i][row_col_size - 1 - j];
         arr[row_col_size - 1 - i][row_col_size - 1 - j] = arr[j][row_col_size - 1 - i];
         arr[j][row_col_size - 1 - i] = ptr;
      }
   }
}
int main(){
   int arr[row_col_size][row_col_size] = { { 5, 1, 4},{ 9, 16, 12 },{ 2, 8, 9}};
   Rotate_ClockWise(arr);
   cout<<"Rotation of a matrix by 90 degree in clockwise direction without using any extra space is: \n";
   for(int i = 0; i < row_col_size; i++){
      for(int j = 0; j < row_col_size; j++){
         cout << arr[i][j] << " ";
      }
      cout << '\n';
   }
   return 0;
}
If we run the above code it will generate the following Output
Rotation of a matrix by 90 degree in clockwise direction without using any extra space is:
2 9 5
8 16 1
9 12 4
#include <bits/stdc++.h>
using namespace std;
#define row_col_size 3
void Rotate_ClockWise(int arr[row_col_size][row_col_size]){
   for(int i = 0; i < row_col_size; i++){
      for(int j = 0; j < row_col_size - i; j++){
         int ptr = arr[i][j];
         arr[i][j] = arr[row_col_size - 1 - j][row_col_size - 1 - i];
         arr[row_col_size - 1 - j][row_col_size - 1 - i] = ptr;
      }
   }
   for(int i = 0; i < row_col_size / 2; i++){
      for(int j = 0; j < row_col_size; j++){
         int ptr = arr[i][j];
         arr[i][j] = arr[row_col_size - 1 - i][j];
         arr[row_col_size - 1 - i][j] = ptr;
      }
   }
}
int main(){
   int arr[row_col_size][row_col_size] = { { 5, 1, 4},{ 9, 16, 12 },{ 2, 8, 9}};
   Rotate_ClockWise(arr);
   cout<<"Rotation of a matrix by 90 degree in clockwise direction without using any extra space is: \n";
   for(int i = 0; i < row_col_size; i++){
      for(int j = 0; j < row_col_size; j++){
         cout << arr[i][j] << " ";
      }
      cout << '\n';
   }
   return 0;
}
If we run the above code it will generate the following Output
Rotation of a matrix by 90 degree in clockwise direction without using any extra space is:
2 9 5
8 16 1
9 12 4