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