-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathselection_sort.c
More file actions
56 lines (49 loc) · 823 Bytes
/
selection_sort.c
File metadata and controls
56 lines (49 loc) · 823 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
53
54
55
56
#include <stdio.h>
int a[100];
int n;
void selection()
{
int i, j, min, temp;
for (i = 0; i < n - 1; i = i + 1)
{
min = i;
for (j = i + 1; j < n; j = j + 1)
{
if (a[j] < a[min])
{
min = j;
}
}
temp = a[i];
a[i] = a[min];
a[min] = temp;
}
}
int main()
{
printf("Enter the size of the array\n");
scanf("%d", &n);
printf("Enter the elements\n");
for (int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
selection();
printf("The Sorted Array is \n");
for (int i = 0; i < n; i++)
printf("%d\t", a[i]);
return 0;
}
/*
OUTPUT
Enter the size of the array
5
Enter the elements
1
45
34
20
-424
The Sorted Array is
-424 1 20 34 45
*/