giving run error, please help
Rotate image nxn array
@lipikarustagi Runtime error is due to your infinite for loop at line 25.Change i++ to i–.
Still i think that your output is wrong.
Follow this approach:
For a given nxn matrix You are needed to perform 2 steps:
-
Take transpose along the diagonal.
This you can do by: if(i!=j) then swap(arr[i][j],arr[j][i]) -
Reverse all rows.
This you can do by: swap(arr[i][j],arr[i][n-1-j])
Try to code by yourself using these conditions and you will get it clear.
Note that this is when you want rotation in clockwise direction by 90 degree.
If you want the rotation in anti clockwise direction, you will have to take transpose along the other diagonal.
Just do some index manipulation and swap the elements. Check for the indexes by considering any example and generalize a formula for swapping elements in order to from the transposed matrix.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.