#include<stdio.h>
int main()
{
int i,j,size,t,a[30];
printf("\tInsertion sort\n");
printf("-----------------------------------\n");
printf(" How many numbers you want to sort?: ");
scanf("%d",&size);
printf("\n Enter %d numbers: \n",size);
for(i=0;i<size;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<=size-1;i++)
{
t=a[i];
j=i-1;
while((t<a[j])&&(j>=0))
{
a[j+1]=a[j]; //moves element forward
j=j-1;
}
a[j+1]=t; //insert element in proper place
}
printf("\n Sorted numbers after using insertion sort: \n\n");
for(i=0;i<size;i++)
{
printf(" %d",a[i]);
}
return 0;
}