Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

How to print every step of Insertion sort in C?

I am new to C language and I know that what happens in insertion sort but I dont know where and what to write for printing every step of insertion sort. Here is my code

#include<stdio.h>
#include<conio.h>
void insert_sort (int a[], int);
int n, a[20];
void main ()
{
  int i;
  clrscr ();
  printf ("Enter size of Array\n");
  scanf ("%d", &n);
  printf ("Enter Elements\n");
  for (i = 0; i < n; i++)
    {
      scanf ("%d", &a[i]);
    }
  insert_sort (a, n);
  printf ("Sorted Array is: ");
  for (i = 0; i < n; i++)
    {
      printf ("%d\t", a[i]);
    }
  printf ("\n");
  getch ();
}

void
insert_sort (int a[], int n)
{
  int i, j, num;
  for (i = 0; i < n; i++)
    {
      num = a[i];
      for (j = i - 1; j >= 0 && num < a[j]; j--)
    {
      a[j + 1] = a[j];
    }
      a[j + 1] = num;
    }
  return;
}

Can anyone please help me out ?

Comments