forked from Abhijeet5665/c-programs-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathm1.c
More file actions
107 lines (84 loc) · 1.3 KB
/
m1.c
File metadata and controls
107 lines (84 loc) · 1.3 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include<stdio.h>
void main(){
int n,m,i,j;
printf("enter the row and column of matrix\n");
scanf("%d%d",&n,&m);
int a[n][m];
printf("eneter the elemnts\n");
for(i=0;i<n;i++){
for(j=0;j<m;j++)
scanf("%d",&a[i][j]);
}
int d[n][m];
printf("cloneing in process......\n");
for(i=0;i<n;i++){
for(j=0;j<m;j++)
d[i][j]=a[i][j];
}
printf("\n");
for(i=0;i<n;i++){
for(j=0;j<m;j++)
printf("%d ",d[i][j]);
printf("\n");
}
int temp,k;
for(i=0;i<n;i++){
for(j=0;j<m;j++){
for(k=j+1;k<m;k++)
{
if(a[i][j]>a[i][k]){
temp=a[i][j];
a[i][j]=a[i][k];
a[i][k]=temp;
}
}
}
}
for(i=0;i<n;i++){
for(j=0;j<m;j++)
printf("%d ",a[i][j]);
printf("\n");
}
printf("---------------------------------------\n\n");
printf("now the second program starts that sorts the cloumns\n");
for(i=0;i<n;i++){
for(j=0;j<m;j++){
for(k=i+1;k<n;k++)
{
if(a[i][j]>a[k][j])
{
temp=a[i][j];
a[i][j]=a[k][j];
a[k][j]=temp;
}
}
}
}
printf("this is the sorting of the ealier sorted matrix that is row sorted\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
printf("%d ",a[i][j]);
printf("\n");
}
printf("now this program sorts coloumn of dummy matrix\n");
for(i=0;i<n;i++){
for(j=0;j<m;j++){
for(k=i+1;k<n;k++)
{
if(d[i][j]>d[k][j])
{
temp=d[i][j];
d[i][j]=d[k][j];
d[k][j]=temp;
}
}
}
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
printf("%d ",d[i][j]);
printf("\n");
}
}