#include<iostream.h>
#include<conio.h>
void insert(int a[],int n,int d,int pos)
{
int i;
for(i=n-1;i>=pos-1;i--)
{
a[i+1]=a[i];
}
a[pos-1]=d;
}
void main()
{
clrscr();
int a[50],i,n,d,pos;
cout<<"Enter the number of elements ";
cin>>n;
cout<<"Enter the elements";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"Enter the element to be inserted and its location";
cin>>d>>pos;
insert(a,n,d,pos);
cout<<"After Insertion";
for(i=0;i<=n;i++)
{
cout<<a[i]<<",";
}
getch();
}
#include<conio.h>
void insert(int a[],int n,int d,int pos)
{
int i;
for(i=n-1;i>=pos-1;i--)
{
a[i+1]=a[i];
}
a[pos-1]=d;
}
void main()
{
clrscr();
int a[50],i,n,d,pos;
cout<<"Enter the number of elements ";
cin>>n;
cout<<"Enter the elements";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"Enter the element to be inserted and its location";
cin>>d>>pos;
insert(a,n,d,pos);
cout<<"After Insertion";
for(i=0;i<=n;i++)
{
cout<<a[i]<<",";
}
getch();
}