C Program to implement Insertion Sort Using Arrays

Insertion Sort Using Arrays


Write a C Program to implement Insertion Sort Using Arrays. Here’s simple C Program to implement Insertion Sort Using Arrays in C Programming Language.


Below is the source code for C Program to implement Insertion Sort Using Arrays which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :


/*  C Program to implement Insertion Sort Using Arrays  */

#include <stdio.h>

int main()
{
        int A[20], N, Temp, i, j;
        printf("\nENTER THE NUMBER OF TERMS...: ");
        scanf("%d",&N);
        printf("\nENTER THE ELEMENTS OF THE ARRAY...: \n");
        for(i=1; i<=N; i++)
        {
            printf("\nENTER THE ELEMENT [ %d ]...: ",i);
            scanf("%d", &A[i]);
        }

        for(i=1; i<N; 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("\nTHE SORTED LIST IS...: \n\n");
        for(i=1; i<=N; i++)
                printf(" %d ",A[i]);

        printf("\n");

        return 0;
}

OUTPUT : :


/*  C Program to implement Insertion Sort Using Arrays  */

ENTER THE NUMBER OF TERMS...: 6

ENTER THE ELEMENTS OF THE ARRAY...:

ENTER THE ELEMENT [ 1 ]...: 2

ENTER THE ELEMENT [ 2 ]...: 5

ENTER THE ELEMENT [ 3 ]...: 1

ENTER THE ELEMENT [ 4 ]...: 9

ENTER THE ELEMENT [ 5 ]...: 0

ENTER THE ELEMENT [ 6 ]...: 7

THE SORTED LIST IS...:

 0  1  2  5  9  7

Process returned 0

Above is the source code for C Program to implement Insertion Sort Using Array which is successfully compiled and run on Windows System.The Output of the program is shown above .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.


Thanks for reading the post….

Leave a Reply