TEAM CODING-BCA

C Program to perform Insertion Sort

C Program to perform Insertion Sort:


#include<stdio.h>
void main()
{
int a[6];
int i,j,temp;
printf("\n Enter The elements of the array:");
for(i=0;i<6;i++)
{
printf("\n enter %d th element :",i);
scanf("%d",&a[i]);
}
for (i=0;i<6;i++)
{
temp=a[i];
j = i-1;
while(temp<a[j]  &&  j>=0)
{
a[j+1] = a[j];
j = j-1;
}
a[j+1] = temp;
}
printf("\n After insertion sort the sorted array is:");
for(i=0;i<6;i++)
{
printf("\n \t %d",a[i]);
}

}
OUTPUT

No comments:

Post a Comment