ovi_salman

Problem No 11

Jul 25th, 2016
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. //You are given an array of n integers and two integers, an index and a value. Replace 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 replacement separated by a newline; array values should be separated by spaces.
  6. #include<iostream>
  7. using namespace std;
  8. int main(){
  9. int a[100],n,p,r;
  10. cin>>n;
  11.  
  12. for(int i=0;i<n;i++){
  13. cin>>a[i];
  14. }
  15. for(int i=0;i<n;i++){
  16. cout<<a[i]<< " ";
  17. }
  18. cout<<endl;
  19. cin>>p>>r;
  20. a[p]=r;
  21.  
  22. cout<<endl;
  23.  
  24. for(int i=0;i<n;i++){
  25. cout<<a[i]<< " ";
  26. }
  27. return 0;
  28. }
Add Comment
Please, Sign In to add comment