Advertisement
Ahmed_Negm

Untitled

Nov 16th, 2022
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. void Fast_IO(){
  4. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  5. // freopen("filename.in", "r", stdin);
  6. // freopen("filename.txt", "w", stdout);
  7. #ifndef ONLINE_JUDGE
  8. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  9. #endif
  10. }
  11.  
  12.  
  13. int main ()
  14. {
  15. Fast_IO();
  16.     int n, i, j, k = 0; // k is intial size of array B
  17.     cout << "Enter size of array : ";
  18.     cin >> n;
  19.     int A[n], B[n];
  20.     cout << "Enter elements of array : ";
  21.     for (i = 0; i < n; i++)
  22.         cin >> A[i];     // input element in array  
  23.  
  24.     for (i = 0; i < n; i++) // loop for traverse the array
  25.     {
  26.         for (j = 0; j < k; j++) // loop for checking the element is present in B array or not
  27.         {
  28.             if (A[i] == B[j]) // if present then break the loop
  29.                 break;
  30.         }
  31.         if (j == k) // if not present in B array then insert it
  32.         {
  33.             B[k] = A[i]; // insert element in B array
  34.             k++; // increment the size of B array
  35.         }
  36.     }
  37.  
  38.     cout << "Repeated elements after deletion : ";
  39.     for (i = 0; i < k; i++)
  40.         cout << B[i] << " "; // print the array B
  41. return 0;
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement