Program 138: Arrange Rows and Columns of Matrix in Ascending order

Program 138:

```#include<stdio.h>
main()
{
int i,j,rows,col,k,temp;
printf("Enter number of rows and columns of a matrix\n");
scanf("%d %d",&rows,&col);
int a[rows][col],dummy[rows][col];

//Taking input of matrix
printf("Enter Matrix 1\n");
for(i=0;i<rows;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&a[i][j]);
}
}

printf("Given /matrix is\n");
for(i=0;i<rows;i++)
{
for(j=0;j<col;j++)
{
printf("%d\t",a[i][j]);
dummy[i][j]=a[i][j];//copying of array into another for temporary storage
}

printf("\n");
}

//Ascending order for rows
for(i=0;i<rows;i++)
{
for(j=0;j<col;j++)
{
for(k=j+1;k<col;k++)
{
if(a[i][j]>a[i][k])
{
temp=a[i][j];
a[i][j]=a[i][k];
a[i][k]=temp;
}
}
}
}

printf("After arranginf rows in ascending order\n");
for(i=0;i<rows;i++)
{
for(j=0;j<col;j++)
{
printf("%d\t",a[i][j]);
}

printf("\n");
}
//For arranging columns in ascending order

for(j=0;j<col;j++)
{
for(i=0;i<rows;i++)
{
for(k=i+1;k<rows;k++)
{
if(dummy[i][j]>dummy[k][j])
{
temp=dummy[i][j];
dummy[i][j]=dummy[k][j];
dummy[k][j]=temp;
}
}
}
}

printf("After arranginf columns in ascending order\n");
for(i=0;i<rows;i++)
{
for(j=0;j<col;j++)
{
printf("%d\t",dummy[i][j]);
}

printf("\n");
}

}
```
Explanation:

//Coming Soon...

Output:

 Donate Buy me a coffee \$2.00 USD Buy me a burger \$5.00 USD Buy me a pizza \$10.00 USD
 Compiler Used by me C-Free 5.0(Recommended) Other Compilers Code Blocks(Recommended) Online Compilers Ideone(Remember to give input before executing online where ever necessary)