Advertisement
alexdmin

7.1

Apr 18th, 2021
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void newarr(int* arr, int lenarr)
  6. {
  7.     for (int i = 0; i < lenarr; i++)
  8.     {
  9.         arr[i] = 0 + rand() % 20;
  10.     }
  11.     cout << "Начальный массив: \n";
  12.     for (int i = 0; i < lenarr; i++)
  13.     {
  14.         cout << arr[i] << " ";
  15.     }
  16.     cout << "\nПолученный массив: \n";
  17.     for (int i = 0; i < lenarr; i++)
  18.     {
  19.         for (int j = i + 1; j < lenarr; j++)
  20.         {
  21.             if (arr[i] == arr[j])
  22.             {
  23.                 int wasBefore = 0;
  24.                 for (int k = 0; k < i; k++) {
  25.                     if (arr[k] == arr[i]) {
  26.                         wasBefore = 1; break;
  27.                     }
  28.                 }
  29.                 if (wasBefore == 0) {
  30.                     cout << arr[i] << " ";
  31.                 }
  32.                 break;
  33.             }
  34.         }
  35.     }
  36.    
  37. }
  38. int main()
  39. {
  40.     setlocale(LC_ALL, "rus");
  41.     int n;
  42.     cout << "Введите число n:\n";
  43.     cin >> n;
  44.     int* arr = new int[n];
  45.     newarr(arr, n);
  46.     delete[]arr;
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement