Thursday 5 February 2015

C++ Program to insert the element in array any position

C++ Program to insert  the element in array any position 

#include<iostream.h>
#include<conio.h>
void main()
{
 int a[10],i,j,m,n,k;
 clrscr();
 cout<<"Enter the length of array:\n";
 cin>>n;
 cout<<"Enter no of elements:\n";
 for(i=0;i<n;i++)
 cin>>a[i];
 cout<<"Enter the position k:\n";
 cin>>k;
 cout<<"Enter the element you want to insert:\n";
 cin>>m;
 for (j=n;j>=k-1;j--)
   {
    a[j+1]=a[j];
    a[j]=m;
   }
   n=n+1;
   for(i=0;i<n;i++)
   cout<<"\n"<<a[i];
  getch();
 }

No comments:

Post a Comment