//*********INSERTION SORT

******//
#include<stdio.h>
#include<conio.h>
void main()
{
int ptr,a[20],k,temp,i,n;
clrscr();
printf("\n\nEnter the no of elements in the array..:");
scanf("%d",&n);
printf("\n\nEnter the element of the array..:");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
a[0]=-1;
for(k=2;k<=n;k++)
{
temp=a[k];
ptr=k-1;
while(temp<a[ptr])
{
a[ptr+1]=a[ptr];
ptr=ptr-1;
}
a[ptr+1]=temp;
}
printf("The sorted array is..\n\n");
for(i=1;i<=n;i++)
{
printf("%d\t",a[i]);
}
getch();
}
OUTPUT
Enter the no of elements in the array..:8
Enter the element of the array..:3 4 2 1 0 7 6 5
The sorted array is..
0

1

2

3

4

5

6

7