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. Replace 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 replacement separated by a newline; array values should be separated by spaces.
- #include<iostream>
- using namespace std;
- int main(){
- int a[100],n,p,r;
- cin>>n;
- for(int i=0;i<n;i++){
- cin>>a[i];
- }
- for(int i=0;i<n;i++){
- cout<<a[i]<< " ";
- }
- cout<<endl;
- cin>>p>>r;
- a[p]=r;
- cout<<endl;
- for(int i=0;i<n;i++){
- cout<<a[i]<< " ";
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment