How do you rotate a two dimensional array?

Answer

Here it is in C#

int[,] array =newint[4,4]{{1,2,3,4},{5,6,7,8},{9,0,1,2},{3,4,5,6}};int[,] rotated =RotateMatrix(array,4);staticint[,]RotateMatrix(int[,] matrix,int n){int[,] ret =newint[n, n];for(int i =0; i < n;++i){for(int j =0; j < n;++j){
            ret[i, j]= matrix[n - j -1, i];}}return ret;}

All algorithm Questions

Ask your interview questions on algorithm

Write Your comment or Questions if you want the answers on algorithm from algorithm Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---