INSERTION SORT PROGRAM

INSERTION SORT
#include<stdio.h>
#include<conio.h>


void main()
{
     int  a[100], n, temp, i, j;
     printf("Enter number of terms(should be less than 100): ");
     scanf("%d",&n);
     printf("Enter elements %d integer values: ",n);

           for(i=0;i<n;i++)
           {
                       scanf("%d", &a[i]);
           }
           for(i=1;i<=n-1;i++)
           {
                       temp = a[i];
                       for(j=i-1; a[j]>temp && j>=0; j--)
                       {
                                   a[j+1] = a[j];
                       }
                       a[j+1]=temp;
           }

     printf("In ascending order: ");
     for(i=0; i<n; i++)
     printf("%d\t", data[i]);

getch();

}
Share on Google Plus
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment