Sun Jun 17 2018

Selection Sort

C Programming872 views

File Name: selection-sort.c

#include<stdio.h>

int main() {
	int data[10], i, j, k, temp;
	printf("Enter 10 random number to sort in ascending order:\n");
	for(i = 0; i < 10; i++)
		scanf("%d", &data[i]);

	/* Sorting process start */
	for(i = 0; i < 9; i++) {
		k = i;
		for(j = i + 1; j < 10; j++) {
			if(data[k] > data[j])
				k = j;
		}
		if(k != i) {
			temp = data[i];
			data[i] = data[k];
			data[k] = temp;
		}
	}
	printf("After sort\n");
	for(i = 0; i < 10; i++)
		printf("%d\n",data[i]);
	return 0;
}



/* Output */
Enter 10 random number to sort in ascending order:
4
6
1
8
3
7
2
5
9
0

After sort
0
1
2
3
4
5
6
7
8
9
Reference:

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.