Showing posts with label Insert element at desired place in array. Show all posts
Showing posts with label Insert element at desired place in array. Show all posts

Monday, September 12, 2011

Insert element at desired place in array

main()
{
int n,i,j,k,temp;
int a[10];
clrscr();
printf("\n Enter number of elements:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter the %d th element",i+1);
scanf("%d",&a[i]);
}
for(j=1;j<n;j++)
   for(i=0;i<j;i++)
    if(a[i]>a[j])
    {
     temp=a[j];
         for(k=j;k>i;k--)
           a[k]=a[k-1];

     a[k]=temp;
     break;
       }
 for(i=0;i<n;i++)
   printf("%d\n",a[i]);
 getch();
 }

Popular 5 Posts Last 7 days