Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. //main.cpp
  2. #include <iostream>
  3. #include "functions.h"
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     const int size1 = 11;
  9.     int set1[size1] = { 5,2,3,8,1,6,4,12,9,10 };
  10.  
  11.     const int size2 = 7;
  12.     int set2[size2] = { 6,12,8,2,5,7,11 };
  13.     cout << "The max num from the 2nd set that does not consist in the 1st is: " << maxNumOfSubSet(set1, set2, size1, size2) << endl;
  14.  
  15.     return 0;
  16. }
  17.  
  18. //functions.cpp
  19.  
  20. #include <iostream>
  21. #include "functions.h"
  22.  
  23. int maxNumOfSubSet(int *set1, int *set2, unsigned size1, unsigned size2)
  24. {
  25.     int max = set2[0];
  26.     bool occurs = false;
  27.     for (int i = 0; i < size1; i++)
  28.     {
  29.         occurs = false;
  30.         for (int k = 0; k < size2; k++)
  31.         {
  32.             if (set1[i] == set2[k])
  33.             {
  34.                 occurs = true;
  35.             }
  36.             if (k == size2 - 1)
  37.             {
  38.                 if (occurs == false)
  39.                 {
  40.                     if (set2[k] > max)
  41.                     {
  42.                         max = set2[k];
  43.                     }
  44.                 }
  45.             }
  46.         }
  47.     }
  48.     return max;
  49. }
  50.  
  51.  
  52. //functions.h
  53.  
  54. #ifndef _H_FUNCTIONS_H_
  55. #define _H_FUNCTIONS_H_
  56.  
  57. int maxNumOfSubSet(int *, int *, unsigned, unsigned);
  58.  
  59. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement