Solution:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void insertionsort(int [],int);
void array(int [],int);
int main()
{
int A[30],n,i;
printf("Enter size of array :\n");
scanf("%d",&n);
array(A,n);
insertionsort(A,n);
printf("\nSorted Array :\n");
for(i=0;i<n;i++)
{
printf("%d\n",A[i]);
}
}
void insertionsort(int A[],int n)
{
int i,j,temp;
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;
}
}
void array(int A[],int n)
{
int i;
srand(time(0));
for(i = 0; i<n; i++)
{
A[i]=rand();
}
printf("Array :\n");
for(i = 0; i<n; i++)
{
printf("%d ",A[i]);
}
printf("\n");
}
0 Comments