We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents d770364 + d88ab79 commit bc32952Copy full SHA for bc32952
sortingAlgo/selectionSort/selectionsort.c
@@ -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