Advertisement
Marufcse

Insertation given index of array

Dec 20th, 2021
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int arr[50], i, elem, pos, tot;
  6.     cout<<"Enter the Size for Array: ";
  7.     cin>>tot;
  8.     cout<<"Enter "<<tot<<" Array Elements: ";
  9.     for(i=0; i<tot; i++)
  10.         cin>>arr[i];
  11.     cout<<"\nEnter Element to Insert: ";
  12.     cin>>elem;
  13.     cout<<"At What Position ? ";
  14.     cin>>pos;
  15.     for(i=tot; i>=pos; i--)
  16.         arr[i] = arr[i-1];
  17.     arr[i] = elem;
  18.     tot++;
  19.     cout<<"\nThe New Array is:\n";
  20.     for(i=0; i<tot; i++)
  21.         cout<<arr[i]<<"  ";
  22.     cout<<endl;
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement