This C Program sorts the rows of the matrix in ascending & columns in descending order. This program accepts matrix. Then sorts the row in an ascending order & the columns in descending order.

Here is source code of the C program to sort rows of the matrix in ascending & columns in descending order. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

`/*`

`* C program to accept a matrics of order MxN and sort all rows of the`

`* matrix in ascending order and all columns in descending order`

`*/`

`#include <stdio.h>`

void main()

`{`

static int array1[10][10], array2[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-efficients of the matrix \n");

for (i = 0; i < m; ++i)

`{`

for (j = 0; j < n; ++j)

`{`

scanf("%d", &array1[i][j]);

array2[i][j] = array1[i][j];

`}`

`}`

printf("The given matrix is \n");

for (i = 0; i < m; ++i)

`{`

for (j = 0; j < n; ++j)

`{`

printf(" %d", array1[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 (array1[i][j] > array1[i][k])

`{`

a = array1[i][j];

array1[i][j] = array1[i][k];

array1[i][k] = a;

`}`

`}`

`}`

`}`

for (i = 0; i < m; ++i)

`{`

for (j = 0; j < n; ++j)

`{`

printf(" %d", array1[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 (array2[i][j] < array2[k][j])

`{`

a = array2[i][j];

array2[i][j] = array2[k][j];

array2[k][j] = a;

`}`

`}`

`}`

`}`

for (i = 0; i < m; ++i)

`{`

for (j = 0; j < n; ++j)

`{`

printf(" %d", array2[i][j]);

`}`

printf("\n");

`}`

`}`

$ cc pgm87.c $ a.out Enter the order of the matrix 3 3 Enter co-efficients of the matrix 3 7 9 2 4 8 5 2 6 The given matrix is 3 7 9 2 4 8 5 2 6 After arranging rows in ascending order 3 7 9 2 4 8 2 5 6 After arranging the columns in descending order 5 7 9 3 4 8 2 2 6

**Sanfoundry Global Education & Learning Series – 1000 C Programs.**

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Matrix, go to C Programming Examples on Matrix. If you wish to look at programming examples on all topics, go to C Programming Examples.