forked from Pavan-Kamthane/C_langauege_
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelectionSort.c
47 lines (44 loc) · 909 Bytes
/
SelectionSort.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
/* SELECTION SORT*/
#include <stdio.h>
#include <conio.h>
int main()
{
int a[100], n, i, j, temp, loc;
// clrscr();
printf("Enter the size of the array\n");
scanf("%d", &n);
printf("Enter the elements of the array\n");
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
printf("The array is: ");
for (i = 0; i < n; i++)
{
printf("%d ", a[i]);
}
for (i = 0; i < n - 1; i++)
{
loc = i;
for (j = i + 1; j < n; j++)
{
if (a[j] < a[loc])
{
loc = j;
}
}
if (loc != i)
{
temp = a[i];
a[i] = a[loc];
a[loc] = temp;
}
}
printf("\nThe Sorted Array is: ");
for(i=0; i<n; i++)
{
printf("%d ",a[i]);
}
//getch();
return 0;
}