Friday, February 17, 2012

Rotate a square matrix counter clockwise by 90 degrees.

Given a KxK array, rotate the array 90 degrees counter-clockwise in place.


Code output:



Original Square Matrix: 
1 2 3 4 
5 6 7 8 
9 10 11 12 
13 14 15 16 


Transpose of the square matrix: 
1 5 9 13 
2 6 10 14 
3 7 11 15 
4 8 12 16 


Matrix Rotated by 90 degrees counter clockwise:
4 8 12 16 
3 7 11 15 
2 6 10 14 
1 5 9 13 

No comments:

Post a Comment