Print matrix by 90 degrees rotation C program

Given a matrix. Rotate it by 90 degrees.

For example if matrix arr[m][n] is


                         11   12   13   14
                         21   22   23   24
arr[m][n]=          31   32   33   34
                        41   42    43   44

then print matrix like

                        41  31  21  11
                        42  32  22  12
                        43  33  23  13
                        44  34  24  14

C Program:

/* C Program to rotate matrix by 90 degrees */
#include<stdio.h>
int main()
{
 int matrix[100][100];
 int m,n,i,j;
 printf("Enter row and columns of matrix: ");
 scanf("%d%d",&m,&n);
 
 /* Enter m*n array elements */
 printf("Enter matrix elements: \n");
 for(i=0;i<m;i++)
 {
  for(j=0;j<n;j++)
  {
   scanf("%d",&matrix[i][j]);
  }
 }
 
 /* matrix after the 90 degrees rotation */
 printf("Matrix after 90 degrees roration \n");
 for(i=0;i<n;i++)
 {
  for(j=m-1;j>=0;j--)
  {
   printf("%d  ",matrix[j][i]);
  }
  printf("\n");
 }
 
 return 0;
 
}


Popular posts from this blog