Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///You are given an array of n integers and two integers, an index and a value. Insert the value in the given index.
- ///Input:
- ///Inputs are positive integer n followed by n integers and two integers, an index and a value.
- ///Output:
- ///Outputs are array values before and after insertion separated by a newline; array values are separated by spaces.
- #include<iostream>
- using namespace std;
- int main(){
- int a[50];
- int i,n,temp,occ,value;
- cin>>n;
- for(i=0;i<n;i++)
- {
- cin>>a[i];
- }
- cin>>occ>>value;
- for(int i=n-1;i>occ;i--)
- {
- temp=a[i];
- a[i]=a[i-1];
- a[i+1]=temp;
- }
- a[occ]=value;
- for(int i=0;i<n+1;i++)
- {
- cout<<a[i]<<" ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement