-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy patharray_2d_sort.c
More file actions
49 lines (43 loc) · 757 Bytes
/
array_2d_sort.c
File metadata and controls
49 lines (43 loc) · 757 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
#include<stdio.h>
#include<conio.h>
int main()
{
int a[3][3], i, j;
int *p = a, temp;
printf("Enter 9 Elements: ");
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
scanf("%d", &a[i][j]);
printf("Given 2D Array:\n");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
printf("%d", a[i][j]);
}
printf("\n");
}
for (i = 0; i < 3; i++)
{
for (j = i + 1; j < 3; j++)
{
if (a[i][j] > a[i][j + 1])
{
temp = a[i][j];
a[i][j] = a[i][j + 1];
a[i][j + 1] = temp;
}
}
printf("\n");
}
printf("Sorted 2D Array:\n");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
printf("%d", a[i][j]);
}
printf("\n");
}
return 0;
}