Skip to content

Commit bc32952

Browse files
authored
Merge pull request deutranium#155 from mashiyathussain2/patch-1
Create selectionsort.c
2 parents d770364 + d88ab79 commit bc32952

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <stdio.h>
2+
3+
void main()
4+
{
5+
int n,c,d,position,swap;
6+
printf("Enter number of elements\n");
7+
scanf("%d",&n);
8+
int array[n];
9+
printf("Enter %d integers\n",n);
10+
for(c=0;c<n;c++)
11+
scanf("%d",&array[c]);
12+
13+
for(c=0;c<(n-1);c++) {
14+
position=c;
15+
for(d=c+1;d<n;d++) {
16+
if(array[position]>array[d])
17+
position=d;
18+
}
19+
if(position !=c) {
20+
swap = array[c];
21+
array[c] = array[position];
22+
array[position] = swap;
23+
}
24+
}
25+
printf("Sorted list in ascending order:\n");
26+
for(c = 0; c<n; c++)
27+
printf("%d\n", array[c]);
28+
getch();
29+
}

0 commit comments

Comments
 (0)