# C Program to sort the matrix rows and columns.

C Program to sort the matrix rows and columns. This C program accept a order MxN Matrix, and sort all rows of the matrix in ascending order and all columns in descending order . In this program, we use the for statement to read two dimension arrays. Read more about C Programming Language .

`/************************************************************ You can use all the programs on  www.c-program-example.com* for personal and learning purposes. For permissions to use the* programs for commercial purposes,* contact [email protected]* To find more C programs, do visit www.c-program-example.com* and browse!* *                                  Happy Coding***********************************************************/#include <stdio.h>void main (){ static int ma,mb; int i,j,k,a,m,n; printf ("Enter the order of the matrix n"); scanf ("%d %d", &m,&n); printf ("Enter co-efficients of the matrix n"); for (i=0;i<m;++i) {  for (j=0;j<n;++j)  {   scanf ("%d",&ma[i][j]);   mb[i][j] = ma[i][j];  } } printf ("The given matrix is n"); for (i=0;i<m;++i) {  for (j=0;j<n;++j)  {   printf (" %d",ma[i][j]);  }  printf ("n"); } printf ("After arranging rows in ascending ordern"); for (i=0;i<m;++i) {  for (j=0;j<n;++j)  {   for (k=(j+1);k<n;++k)   {    if (ma[i][j] > ma[i][k])    {     a = ma[i][j];     ma[i][j] = ma[i][k];     ma[i][k] = a;    }   }  } }      /* End of outer for loop*/ for (i=0;i<m;++i) {  for (j=0;j<n;++j)  {   printf (" %d",ma[i][j]);  }  printf ("n"); } printf ("After arranging the columns in descending order n"); for (j=0;j<n;++j) {  for (i=0;i<m;++i)  {   for (k=i+1;k<m;++k)   {    if (mb[i][j] < mb[k][j])    {     a = mb[i][j];     mb[i][j] = mb[k][j];     mb[k][j] = a;    }   }  } }       /* End of outer for loop*/ for (i=0;i<m;++i) {  for (j=0;j<n;++j)  {   printf (" %d",mb[i][j]);  }  printf ("n"); }}  /*End of main() */`
`Read more Similar C ProgramsC Basic.C Matrix.`

You can easily select the code by double clicking on the code area above.