My photo
Bangalore, Karnataka, India
Extending one hand to help someone has more value rather than joining two hands for prayer

Archives

program to insert the element in the array

Tuesday, September 1, 2009

#include<iostream.h>
#include<conio.h>
void main()
{
 clrscr();
 int a[100],n,pos,item;
 cout<<"enter the total number of elements ";
 cin>>n;
 for(int i=0;i<n;i++)
 {
  cout<<"enter the '"<<i<<"'th position element ";
  cin>>a[i];
  }
  cout<<"enter the position at which the element to be inserted: ";
  cin>>pos;
  if(pos<=n)
  {
  cout<<"enter the element to be inserted: ";
  cin>>item;
  a[pos]=item;
  for(i=n+1;i>pos;i--)
  { a[i+1]=a[i];}
  cout<<"elements after insertion is"<<endl;
  for(i=0;i<=n;i++)
  cout<<a[i]<<"  ";
  }
  else
  cout<<"array could not be filled by jumping one or more position";
  getch();
  }

0 comments: