When matrix is rotated degrees clockwise, the element at position moves to the position (j, n - i - 1) in matrix .
If the original matrix has dimensions n \times m, then the resulting matrix will have dimensions m \times n. The indexing of elements in both matrices starts from .
Algorithm implementation
Declare the input array and the resulting reversed array .
#define MAX 55
int a[MAX][MAX], b[MAX][MAX];Read the input data.
scanf("%d %d",&n,&m);
for(i = 0; i < n; i++)
for(j = 0; j < m; j++)
scanf("%d",&a[i][j]);Reverse array and store the result in .
for(i = 0; i < n; i++)
for(j = 0; j < m; j++)
b[j][n-i-1] = a[i][j];Print the reversed array .
printf("%d %d\n",m,n);
for(i = 0; i < m; i++)
{
for(j = 0; j < n; j++)
printf("%d ",b[i][j]);
printf("\n");
}