C program to insert an element into an array in any position .

#include<conio.h>
#include<stdio.h>
int main()
{
    int i,k=0,a[100],n,loc,b,j;
    printf(“enter the array size: “);
    scanf(“%d”,&n);
    printf(“enter the element: “);
    for(i=1;i<=n;i++)
    {
     scanf(“%d”,&a[i]);
     }
    printf(“enter the location “);
    scanf(“%d”,&loc);
    loc=loc-1;
    printf(“enter the element::”);
    scanf(“%d”,&b);
    for(j=n;j>=loc;j–)
    {
      a[j+1]=a[j];
      }
    a[loc]=b;
    n=n+1;
    printf(“after implementation :\n”);
    for(i=0;i<n;i++)
    {
     printf(“%d\n”,a[i]);
                    }
  getch();
}

OUTPUT

You might be also interested in :

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s