-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselection.c
44 lines (44 loc) · 898 Bytes
/
selection.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
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,n,temp,mid_index,min;
int a[20];
printf("Enter the no of terms:");
scanf("%d",&n);
printf("\n Enter the elements in array:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\n Array before sorting:");
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
for(i=0;i<n-1;i++)
{
min=a[i];
mid_index=i;
for(j=(i+1);j<n;j++)
{
if(a[j]<min)
{
min=a[j];
mid_index=j;
}
}
if(mid_index!=i)
{
temp=a[i];
a[i]=a[mid_index];
a[mid_index]=temp;
}
}//end of loop
printf("\n Array after sorting:");
for(i=0;i<n;i++)
{
printf("%d\t", a[i]);
}
return 0;
}