You are on page 1of 1

#include<stdio.

h>
#include<conio.h>
void main()
{
int a[10],j,n,i,temp;
int swap,key ,min;
clrscr();
printf("\n enter the no. of element to insert in array ");
scanf("%d",&n);
printf("\n enter the elements to insert in array");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}

//logic of sorting by insertion sort


for(i=1;i<n;i++)
{
key=a[i];
j=i-1;
while((j>=0)&&(a[j]>key))
{
a[j+1]=a[j];
j=j-1;
}
a[j+1]=key;
}

printf("\n after the sorting an array");


for(i=0;i<n;i++)
{
printf("\n %d",a[i]);
}

getch();
}

You might also like