Solved programming problem

How to Sort an Array Using Insertion Method in C.

Source code

#include <stdio.h>

int main()

{

     int array[100],n,m,i,j;

     int item;

     printf("Please Enter The Array Size: ");

     scanf("%d",&n);

         scanf("%d",&array[i]);

     }

     ///insertion sort

     for(i=1;i<n;i++)

     {

        item = array[i];

        j = i-1;

        while( j>=0  && array[j]>item)

        {

            array[j+1]= array[j];

            j=j-1;

        }

        array[j+1]=item;

     }

     for(i=0;i<n;i++)

     {

         printf("%d ",array[i]);

     }

    return 0;

}

Output

Please Enter The Array Size:5

5 3 1 7 3

1 3 3 5 7

Join the discussion

Add your comment

1 previous comment

mahir

goooooood