Q:

C Program to implement Insertion Sort Using Arrays

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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 .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Program to Sort Numbers using Selection sort... >>
<< C Program to implement Insertion Sort Using Linked...