Advertisement
jelyslime

Zad3:pechatane na 1ci na chetna/nechetna poziciq

Jan 27th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int printArray(int * arr, unsigned sz) {
  6.     for (unsigned i = 0; i < sz; i++) {
  7.         cout << arr[i] << "\t";
  8.     }
  9.     cout << endl;
  10.     return 0;
  11. }
  12.  
  13. void genElemKSet(int * uset, int * set, unsigned sz, int pos, unsigned curr) {
  14.     if (curr == sz) printArray(set, sz);
  15.     else {
  16.         if (curr % pos == 0) {
  17.             set[curr] = 0;
  18.             genElemKSet(uset, set, sz, pos, curr + 1);
  19.             set[curr] = 1;
  20.             genElemKSet(uset, set, sz, pos, curr + 1);
  21.         }
  22.         else {
  23.             set[curr] = 1;
  24.             genElemKSet(uset, set, sz, pos, curr + 1);
  25.         }
  26.     }
  27. }
  28.  
  29.  
  30. void genElemKSet(int * uset, int * set,unsigned* poslArr,unsigned razmer, unsigned poziciq , unsigned sz, int elem, unsigned curr,unsigned currZaArr);
  31.  
  32. int main()
  33. {
  34.     const unsigned sz = 5;
  35.     int uarr[sz] = { 1, 2, 3, 4, 5 };
  36.     char bitmaskA[] = "10110";
  37.    
  38.  
  39.     int subset[sz];
  40.     cout << "Genetate all subsets of the universal set, that have are nechetni mamkamu: " << endl;
  41.     genElemKSet(uarr,subset,sz,2,0);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement