41)Write a C program to sort the record of n employee on key employee number using insertion sort method.


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int a[10];
int i,j,k,temp,n;
clrscr();
printf(“\n\n\n How many employees numbers you want\n\n”);
scanf(“%d”,&n);
printf(“\n Enter employees numbers\n”);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
printf(“\n\n Employees numbers are\n\n”);
for(i=0;i<n;i++)
printf(“%d\t”,a[i]);
for(i=1;i<n;i++)
{
temp=a[i];
k=i-1;
while((k>=0)&&(a[k]>temp))
{
a[k+1]=a[k];
k=k-1;
}
a[k+1]=temp;
}
printf(“\n\n array after insertion sorting\n\n”);
for(i=0;i<n;i++)
printf(“%d\t”,a[i]);
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s