C PROGRAM TO INSERT AN ELEMENT IN SORTED ARRAY BY MEANS OF INFORMATION


#include<stdio.h>
#include<conio.h>
void main( )
{
     int a[10],n,item,i;
     clrscr();

     printf("Enter the size of the array: ");
     scanf("%d",&n);
    
     printf("Enter elements of the array in the sorted order\n");
     for(i=0; i<n; i++)
     {
            scanf("%d", &a[i]);
     }
    
     printf("Enter ITEM to be inserted : ");
     scanf("%d", &item);
    
     i = n-1;
     while(item<a[i] && i>=0)
     {
           a[i+1] = a[i];
           i--;
     }
     a[i+1] = item;
     n++;
    
     printf("After insertion array is :\n");
     for(i=0; i<n-1; i++)
     {
              printf("%d\n", a[i]);
     }
     getch();

}    

Output: