This is the simplest insertion sort program. Unfortunately, it doesn't provide an outcome: it does prompt the user for the size of the array and for the list of numbers, but it doesn't do the sort. I would be grateful for your help!
/** Insertion sort **/
#include <stdio.h>
int main (void)
{
int size, array[80], i, j, element;
printf("Enter number of elements: \n");
scanf ("%d", &size);
printf("Enter %d integers\n", size);
for (i = 0; i < size; i++)
{
scanf("%d", &array[i]);
}
for (i = 0; i < size; i++)
{
element = array[i];
j = i;
while (j > 0 && array[j-1] > element)
{
array[j] = array[j-1];
array[j-1] = element;
j--;
}
}
printf ("Sorted list in ascending order:\n");
for (i = 0; i < size; i++)
printf ("%d", array[i]);
return 0;
}