-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMAT_SORT.CPP
More file actions
52 lines (50 loc) · 906 Bytes
/
MAT_SORT.CPP
File metadata and controls
52 lines (50 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<iostream.h>
#include<conio.h>
void main()
{int a[10][10],m,n,i,j;
clrscr();
cout<<"Enter the order of the matrix "<<endl;
cin>>m>>n;
cout<<"Enter the elements of the matrix "<<endl;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>a[i][j];
cout<<"The matrix you entered is "<<endl;
for(i=0;i<m;i++)
{cout<<endl;
for(j=0;j<n;j++)
cout<<a[i][j]<<"\t";
}
cout<<endl;
int temp,k;
for(k=0;k<m;k++)
{
for(i=0;i<n-1;i++)
{ for(j=0;j<n-i-1;j++)
{if(a[k][j]>a[k][j+1])
{temp=a[k][j];
a[k][j]=a[k][j+1];
a[k][j+1]=temp;
}
}
}
}
for(k=0;k<n;k++)
{ for(i=0;i<m-1;i++)
{for(j=0;j<m-i-1;j++)
{if(a[j][k]>a[j+1][k])
{temp=a[j][k];
a[j][k]=a[j+1][k];
a[j+1][k]=temp;
}
}
}
}
cout<<"The sorted matrix is "<<endl;
for(i=0;i<m;i++)
{cout<<endl;
for(j=0;j<n;j++)
cout<<a[i][j]<<"\t";
}
getch();
}