C program to accept a amtric of order MxN and sort all rows of the matrix in ascending order and all columns in descendng order

by Nideesh C on April 13, 2011 · 0 comments

in C Programming




/*  C program to accept a amtric of order MxN and sort all rows of the matrix in ascending order and all columns in descendng order */

#include <stdio.h>

void main ()
{
static int ma[10][10],mb[10][10];
int i,j,k,a,m,n;

printf (“Enter the order of the matrix \n”);
scanf (“%d %d”, &m,&n);

printf (“Enter co-efficient s 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 order\n”);
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() */

/*————————————————-
Enter the order of the matrix
2 2
Enter co-efficient s of the matrix
3 1
5 2
The given matrix is
3 1
5 2
After arranging rows in ascending order
1 3
2 5
After arranging the columns in descending order
5 2
3 1
—————————————————–*/

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program to accept a matrix of given order and interchange any two rows and columns in the original matrix
  2. C program to accept a matrix of order MxN and find its transpose
  3. C program to accept a matrix of order MxN and find the trace and normal of a matrix HINT:Trace is defined as the sum of main diagonal elements and Normal is defined as square root of the sum of all the elements
  4. C program to accept N numbers and arrange them in an ascending order
  5. C program to read A (MxN), find the transpose of a given matrix and output both the input matrix and the transposed matrix.

Leave a Comment

Previous post:

Next post: