Advertisement
STANAANDREY

prod cart

Nov 3rd, 2020
2,090
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. char sp4[] = "";
  4.  
  5. int x4[20], n4, nrsol4 = 0, a[20];
  6.  
  7. void Afisare4() {
  8.   int i, j;
  9.   cout << sp4;
  10.   for (i = 1; i <= n4; i++) cout << x4[i] << " ";
  11.   cout << endl;
  12.   nrsol4++;
  13. }
  14.  
  15. void BackRec4(int k) {
  16.   int i;
  17.   for (i = 1; i <= a[k]; i++) {
  18.     x4[k] = i;
  19.     if (k == n4)
  20.       Afisare4();
  21.     else
  22.       BackRec4(k + 1);
  23.   }
  24. }
  25.  
  26. int main() {
  27.   int i;
  28.   cout << endl
  29.        << endl
  30.        << sp4 << "Produsul cartezian a n multimi de cardinal a1, a2, ... an"
  31.        << endl;
  32.   cout << endl << sp4 << " Dati valoarea lui n: ";
  33.   cin >> n4;
  34.   cout << endl << sp4 << " Dati cardinalul fiecarei multimi: " << endl << endl;
  35.   for (i = 1; i <= n4; i++) {
  36.     cout << sp4 << " Multimea " << i << ": ";
  37.     cin >> a[i];
  38.   }
  39.   BackRec4(1);
  40.   cout << endl << sp4 << "Numar solutii: " << nrsol4;
  41.   return 0;
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement