Sunday , December 11 2016
Home / C / C program for Insertion Sort

C program for Insertion Sort


This is a  c programdemonstrating Insertion Sort using  C.


//This mode is to sort the elements in Insertion Sort order


#include
#include
#include
void main()
{
int a[500];
int key,i,j=2,n,k;
clrscr();

printf(“enter the size of array”);
scanf(“%d”,&n);

printf(“enter the elements\n”);
for(i=0;i
a[i]=random(n);  //you can also input the value of numbers to be sorted
for(i=1;i
{           k=i;
key=a[i];
j=i-1;
while(j>=0 && key
{
a[j+1]=a[j];
k=j;
j–;
}
a[k]=key;
}
for(i=0;i
printf(“%d\t”,a[i]);
getch();
}


OUTPUT

\

tags: c program for sorting technique , sorting using insertion sort , Insertion sort program in C, program in c for sorting

Also See:   c program to find the square root of a number without using sqrt()

Check Also

Hide Mouse Pointer C Program

How to Hide a Mouse Pointer Program in C : This program will show and hide ...

Leave a Reply

Your email address will not be published. Required fields are marked *

Preventing spam * Time limit is exhausted. Please reload the CAPTCHA.