Sat Jun 16 2018

Insertion Sort

C Programming877 views

File Name: insertion-sort.c

#include<stdio.h>

int main() {
	int data[10], i, j, 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 = 1; i < 10; i++) {
		for(j = i; j > 0; j--) {
			if(data[j] < data[j-1]) {
				temp = data[j-1];
				data[j-1] = data[j];
				data[j] = 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.