Advertisement
dstamatova

section

Jan 2nd, 2022
1,246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. // Alg 2-section.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. int* section(int* arr1, int m, int* arr2, int n)
  8. {
  9.     int index = 0;
  10.     int* sectArray = new int [];
  11.  
  12.     for (int i = 0; i < m; i++)
  13.     {
  14.         for (int j = 0; j < n; j++)
  15.         {
  16.             if (arr1[i] == arr2[j])
  17.             {
  18.                 sectArray[index++] = arr1[i];
  19.             }
  20.         }
  21.     }
  22.     return sectArray;
  23. }
  24.  
  25. int main()
  26. {
  27.     int m = 4, n = 5;
  28.  
  29.     int* arr1 = new int [m] { 1, 2, 7, 5 };
  30.     int* arr2 = new int [n] { 2, 1, 3, 5, 0, 8 };
  31.  
  32.     int* sectArray = section(arr1, m, arr2, n);
  33.  
  34.     for (int i = 0; i < 3; i++)
  35.     {
  36.         cout << sectArray[i] << " ";
  37.     }
  38. }
  39.  
  40.  
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement