Advertisement
Md_hosen_zisad

insert array

Mar 18th, 2018
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int  main()
  4. {
  5.  
  6.     int arr[50], size, insert, i, pos;
  7.     cout<<"Enter Array Size : ";
  8.     cin>>size;
  9.     cout<<"Enter array elements : ";
  10.     for(i=0; i<size; i++)
  11.     {
  12.         cin>>arr[i];
  13.     }
  14.     cin>>insert;
  15.  
  16.     cin>>pos;
  17.     for(i=size; i>pos; i--)
  18.     {
  19.         arr[i]=arr[i-1];
  20.     }
  21.     arr[pos]=insert;
  22.     cout<<"Element inserted successfully..!!\n";
  23.     cout<<"Now the new array is : \n";
  24.     for(i=0; i<size+1; i++)
  25.     {
  26.         cout<<arr[i]<<" ";
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement