Advertisement
Md_hosen_zisad

insert array new

Mar 23rd, 2018
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int a[100];
  4. int main()
  5. {
  6.     int n,j,i,x,item;
  7.     cin>>n;
  8.     vector<int>ar;
  9.     for(i=0;i<n;i++)
  10.     {
  11.         cin>>x;
  12.         ar.push_back(x);
  13.     }
  14.     cout <<"enter position";
  15.     cin>>j;
  16.     cout<<"enter item";
  17.     cin>>item;
  18.     for(i=j;i<=n;i++)
  19.     {
  20.         a[i+1]=ar[i];
  21.         a[j]=item;
  22.     }
  23.     for(i=0;i<j;i++)
  24.     {
  25.         a[i]=ar[i];
  26.  
  27.     }
  28.     for(i=0;i<n;i++)
  29.     {
  30.         cout<<a[i]<<" ";
  31.     }
  32.     return 0;
  33.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement