Advertisement
ovi_salman

Problem No 17

Jul 30th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. ///You are given an array of n integers and two integers, an index and a value. Insert the value in the given index.
  2. ///Input:
  3. ///Inputs are positive integer n followed by n integers and two integers, an index and a value.
  4. ///Output:
  5. ///Outputs are array values before and after insertion separated by a newline; array values are separated by spaces.
  6.  
  7.  
  8. #include<iostream>
  9. using namespace std;
  10.  
  11. int main(){
  12. int a[50];
  13. int i,n,temp,occ,value;
  14.  
  15.  
  16. cin>>n;
  17. for(i=0;i<n;i++)
  18. {
  19. cin>>a[i];
  20. }
  21. cin>>occ>>value;
  22.  
  23. for(int i=n-1;i>occ;i--)
  24. {
  25. temp=a[i];
  26. a[i]=a[i-1];
  27. a[i+1]=temp;
  28. }
  29. a[occ]=value;
  30.  
  31. for(int i=0;i<n+1;i++)
  32. {
  33. cout<<a[i]<<" ";
  34. }
  35.  
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement