Advertisement
ovi_salman

Problem No 15

Jul 25th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. //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.
  2. //Input:
  3. //Inputs are positive integer n followed by n integers and an integer value to be deleted.
  4. //Output:
  5. //Outputs are array values before and after deletion separated by a newline; array values are separated by spaces.
  6.  
  7.  
  8. #include<iostream>
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. int a[100],value,n,temp,counter=0;
  14. cin>>n;
  15.  
  16. for(int i=0; i<n; i++)
  17. {
  18. cin>>a[i];
  19. }
  20. cout<<endl;
  21.  
  22.  
  23. for(int i=0; i<n; i++)
  24. {
  25. cout<<a[i]<<" ";
  26. }
  27. cout<<endl;
  28. cin>>value;
  29.  
  30. for(int i=0; i<n; i++)
  31. {
  32. if(a[i]==value){
  33. temp=a[i];
  34. a[i]=a[i+1];
  35. a[i+1]=temp;
  36. counter++;
  37. }
  38. }
  39.  
  40. for(int i=0; i<n-counter; i++)
  41. {
  42. cout<<a[i]<<" ";
  43. }
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement