-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort.c
51 lines (43 loc) · 900 Bytes
/
sort.c
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
#include <stdio.h>
int main(void)
{
int a[10] = {0};
int pass,i,hold,element,n,c;
c =0;
// input array
printf("Enter number of elements : ");
scanf("%d",&n);
while (c<n)
{
printf("Enter element %d : ",c+1);
scanf("%d",&element);
a[c] = element;
c+=1;
}
//original
printf("Data items in original order\n");
for (i = 0; i < n; i++ )
{
printf("%4d", a[ i ] );
}
/* bubble sort */
for ( pass = 1; pass < n; pass++)
{
for (i=0; i < n - 1; i++)
{
if (a[i]> a[i+1])
{
hold = a[ i ];
a[i]=a[i + 1];
a[i+1] = hold;
}
}
}
printf("\nData items in ascending order\n");
for (i = 0; i < n; i++ )
{
printf("%4d", a[ i ] );
}
printf("\n" );
return 0;
}