C program for Insertion Sort Algorithm

# C program for Insertion Sort Algorithm

2098
2
SHARE

C program for Insertion Sort Algorithm :  Insertion sort is an example of an incremental algorithm. It builds the sorted sequence or list one number at a time. This is perhaps the simplest example of the incremental insertion technique, where we build up a complicated structure on n items by first building it on n − 1 items and then making the necessary changes to fix things in adding the last item. The given sequences are normally stored in arrays.  Let us see how to write a .

### C program for Insertion Sort Algorithm  :

```#include<stdio.h>
#include<conio.h>
#include <stdio.h>

int main()
{
int i,n, array[20], c, d, t;
printf("-----------------------------------------------------------\n");
printf("-----------------------------------------------------------\n\n");
printf("\t\tINSERTION SORT ALGORITHM\n\n\n\n");
printf("Enter the number of input : ");
scanf("%d",&n);
printf("\n\nEnter the elements to be sorted :\n");
for ( i = 0; i < n; i++)
{
scanf("%d",&array[i]);
}

for (c = 1 ; c <= n - 1; c++) {
d = c;

while ( d > 0 && array[d] < array[d-1]) {
t          = array[d];
array[d]   = array[d-1];
array[d-1] = t;

d--;
}
}
printf("\n\nSorted List by Insertion Sort :\n");
for ( i = 0; i < n; i++)
{
printf("%d\t",array[i]);
}
getch();
return 0;
}```

We hope you all have enjoyed the of Insertion Sort Algorithm. If you have any queries or issues regarding the above code, ask us in form of comments..

SHARE
Previous articleC program of Heap Sort Algorithm | C code champ
Well, I am software programmer and love to code. My hobbies is to do Hacking, Coding, Blogging, Web Designing and playing online games. Feel free to contact me at shiviskingg@gmail.com or lokesh@hackingloops.com