Facebook
From Gentle Partdridge, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 47
  1. #include <iostream>
  2. using namespace std;
  3. void afisare(int sol[], int lg){
  4.   for(int j = 1; j <= lg; ++j)
  5.     cout << sol[j] << ' ';
  6.   cout << endl;
  7. }
  8. void bkt(int s, int n, int i, int sol[])
  9. {
  10.   for(int j = 1; j <= n; ++j)
  11.   {
  12.     sol[i] = j;
  13.     if(s  + j <= n)
  14.     {
  15.       if(s + j == n)
  16.         afisare(sol, i);
  17.       else
  18.         bkt(s + j, n, i+ 1, sol);
  19.     }
  20.   }
  21. }
  22. int main()
  23. {
  24.   // se da un numar n natural sa se afiseze toate perechile de numere posibile care insumate dau numarul n (ordinea nu conteaza)
  25.   int n, s = 0, sol[100]; cin >> n;
  26.   bkt(s, n, 1, sol);
  27.   return 0;
  28. }
  29.