Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Alg 2-section.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include <iostream>
- using namespace std;
- int* section(int* arr1, int m, int* arr2, int n)
- {
- int index = 0;
- int* sectArray = new int [];
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- if (arr1[i] == arr2[j])
- {
- sectArray[index++] = arr1[i];
- }
- }
- }
- return sectArray;
- }
- int main()
- {
- int m = 4, n = 5;
- int* arr1 = new int [m] { 1, 2, 7, 5 };
- int* arr2 = new int [n] { 2, 1, 3, 5, 0, 8 };
- int* sectArray = section(arr1, m, arr2, n);
- for (int i = 0; i < 3; i++)
- {
- cout << sectArray[i] << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement