Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main() {
- int arr1[] = {1, 2, 3, 4, 5};
- int arr2[] = {3, 4, 5, 6, 7};
- int size1 = sizeof(arr1) / sizeof(arr1[0]);
- int size2 = sizeof(arr2) / sizeof(arr2[0]);
- vector<int> common;
- for (int i = 0; i < size1; i++) {
- for (int j = 0; j < size2; j++) {
- if (arr1[i] == arr2[j]) {
- if (find(common.begin(), common.end(), arr1[i]) == common.end()) // Уникнення дублікатів
- common.push_back(arr1[i]);
- }
- }
- }
- cout << "Спільні елементи: ";
- for (int num : common) {
- cout << num << " ";
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment