Question description Selvan studies, engineering as per his father's wishes, while Aaron, whose family is poor, studies engineering to improve his family's financial situation. sumanth, however, studies engineering of his simple passion for developing data structure applications. sumanth is participating in a hackathon for data structure application development. sumanth task is to use Insertion Sort to sort the supplied set of numbers. As a result, The input provides the number of components on the first line and the numbers to be sorted on the second line. Print the array's state at the third iteration and the final sorted array in the supplied format in the output. Judge will determine whether the outcome is correct or not. Can you help him ?
C Program


#include<stdio.h>

void printArray(int arr[],int n)

{

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

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

    printf("\n");

}

void insertionSort(int arr[],int n)

{

    int i,key,j;

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

    {

        key = arr[i];

        j = i-1;

        while(j>=0 && arr[j] > key)

        {

            arr[j+1] = arr[j];

            j--;

        }

        arr[j+1] = key;

        if(i==2)        // 3rd iteration (i starts from 1)

            printArray(arr,n);

    }

    printArray(arr,n);

}

int main()

{

    int n;

    scanf("%d",&n);

    int arr[n];

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

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

    insertionSort(arr, n);

    return 0;

}