C program to enter a element into sorted array

#include<stdio.h>
#include<conio.h>
void main()
{
 int x[100],y,j,i,z,v,q,s;
 clrscr();
 printf("Enter size of array:- ");
 scanf("%d",&y);
 printf("Enter Elements in array:- \n");
 for(i=0;i<y;i++)
 {
  scanf("%d",&x[i]);
 }
 for(i=0;i<y;i++)
  {
     for(j=i+1;j<y;j++)
      {
       if(x[i]>x[j])
	{
	 v=x[j];
	 x[j]=x[i];
	 x[i]=v;
	}
      }
  }
 printf("Sorted array is:- \n");
 for(i=0;i<y;i++)
  {
    printf("%d \n",x[i]);
  }

  printf("Enter Location you want to insert:-");
  scanf("%d",&s);

  printf("Enter Number:- ");
  scanf("%d",&q);

  for(i=y;i>=s;i--)
    {
     x[i]=x[i-1];
    }
    y++;
    x[s-1]=q;

    for(i=0;i<y;i++)
     {
      printf("%d \n",x[i]);

     }

 getch();
}

OUTPUT:-

sort

insert

Leave a Reply

Your email address will not be published. Required fields are marked *