Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //main.cpp
- #include <iostream>
- #include "functions.h"
- using namespace std;
- int main() {
- const int size1 = 11;
- int set1[size1] = { 5,2,3,8,1,6,4,12,9,10 };
- const int size2 = 7;
- int set2[size2] = { 6,12,8,2,5,7,11 };
- cout << "The max num from the 2nd set that does not consist in the 1st is: " << maxNumOfSubSet(set1, set2, size1, size2) << endl;
- return 0;
- }
- //functions.cpp
- #include <iostream>
- #include "functions.h"
- int maxNumOfSubSet(int *set1, int *set2, unsigned size1, unsigned size2)
- {
- int max = set2[0];
- bool occurs = false;
- for (int i = 0; i < size1; i++)
- {
- occurs = false;
- for (int k = 0; k < size2; k++)
- {
- if (set1[i] == set2[k])
- {
- occurs = true;
- }
- if (k == size2 - 1)
- {
- if (occurs == false)
- {
- if (set2[k] > max)
- {
- max = set2[k];
- }
- }
- }
- }
- }
- return max;
- }
- //functions.h
- #ifndef _H_FUNCTIONS_H_
- #define _H_FUNCTIONS_H_
- int maxNumOfSubSet(int *, int *, unsigned, unsigned);
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement