answersLogoWhite

0

#include<stdio.h>

main()

{

printf("Enter Order Of The Matrix\n");

int l,m;

int i,j,k,t,x;

scanf("%d%d",&l,&m);

int a[l][m],temp[l*m];

printf("Enter The Elements Row Wise...\n");

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

{

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

{

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

}

}

printf("Matrix A \n ");

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

{

printf("\n");

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

{

printf("%d\t",a[i][j]);

}

}

/*----------------------------------------------------------------------*/

x=0;

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

{

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

{

temp[x]=a[i][j];

x++;

}

}

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

{

for(j=0;j<(l*m)-1;j++)

{

if(temp[j]>temp[j+1])

{

t=temp[j];

temp[j]=temp[j+1];

temp[j+1]=t;

}

}

}

x=0;

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

{

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

{

a[i][j]=temp[x];

x++;

}

}

printf("\nMatrix A After Sort \n ");

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

{

printf("\n");

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

{

printf("%d\t",a[i][j]);

}

}

}

User Avatar

Wiki User

11y ago

Still curious? Ask our experts.

Chat with our AI personalities

FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran
RafaRafa
There's no fun in playing it safe. Why not try something a little unhinged?
Chat with Rafa
ReneRene
Change my mind. I dare you.
Chat with Rene

Add your answer:

Earn +20 pts
Q: Write a c program to sort the elements of the matrix in ascending order?
Write your answer...
Submit
Still have questions?
magnify glass
imp