Advertisement
Daniel_leinaD

Пересечение массивов

Apr 19th, 2022
921
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int const n = 10;
  6. int a[n], b[n], c[n];
  7. int q = 0; // кол-во пересечений
  8.  
  9.  
  10. int main() {
  11.     setlocale(LC_ALL, "Rus");
  12.     for (int i = 0; i < n; i++) {
  13.         a[i] = rand() % 10;
  14.         cout << setw(4) << a[i];
  15.     }
  16.     cout << '\n';
  17.  
  18.     for (int i = 0; i < n; i++) {
  19.         b[i] = rand() % 10;
  20.         cout << setw(4) << b[i];
  21.     }
  22.     cout << '\n';
  23.  
  24.     for (int i = 0; i < n; i++) {
  25.         for (int j = 0; j < n; j++) {
  26.             if (a[i] == b[j]) {
  27.                 cout << a[i] << ' ' << b[j] << '\n';
  28.                 c[i] = a[i];
  29.             }
  30.         }
  31.     }
  32.     //* самое интересное, Некит, не проеби
  33.     for (int i = 0; i < n; i++) {
  34.         if (c[i] != 0) {
  35.             q++;
  36.         }
  37.         cout << setw(4) << c[i];
  38.     }
  39.     cout << '\n' << "Число совпадений " << q << '\n';
  40.     int* prt_q = new int[q];
  41.     for (int i = 0; i < n; i++) {
  42.         for (int j = 0; j < 1; j++) {
  43.             if (c[i] != 0) {
  44.                 prt_q[j] = c[i];
  45.                 cout << setw(4) << prt_q[j];
  46.             }
  47.         }
  48.     }
  49.     delete[] prt_q;
  50. }
  51.  
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement