-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcol_sort_largest.c
More file actions
61 lines (58 loc) · 1.02 KB
/
Copy pathcol_sort_largest.c
File metadata and controls
61 lines (58 loc) · 1.02 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
#include<stdio.h>
#define MAX 100
void swap(int *a,int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}
void bsort(int *arr,int *idx,int n)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n-i-1;j++)
{
if(arr[j] > arr[j+1])
{
swap(&arr[j],&arr[j+1]);
swap(&idx[j],&idx[j+1]);
}
}
}
}
int main(void)
{
int r,c,i,j,k,max,arr[MAX][MAX],col[MAX],idx[MAX];
scanf("%d %d",&r,&c);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&arr[i][j]);
}
}
for(j=0;j<c;j++)
{
max = 0;
for(i=0;i<r;i++)
{
if(arr[i][j] > max)
{
max = arr[i][j];
col[j] = max;
idx[j] = j;
}
}
}
bsort(col,idx,c);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
k=idx[j];
printf("%d ",arr[i][k]);
}
printf("\n");
}
return 0;
}