SHARE
TWEET

Untitled

a guest Jan 15th, 2020 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream.h>
  2. using namespace std;
  3. int P[10] ,C[10],n,k,Z[10];
  4.  
  5. void Print()
  6. {for(int i=1;i<=k;i++)
  7.      cout<<Z[P[i]]<<" ";
  8.      cout<<endl;
  9. }
  10. void Permutacii(int p)
  11. {for(int i=1;i<=k;i++)
  12. {P[p]=i;
  13. int j=1;while(P[j]!=i)j++;
  14. if(j==p)if(p<k)Permutacii(p+1);
  15. else Print();
  16. }
  17. }
  18. void Combinacii(int p,int i)
  19. {while(i<n-k+p)
  20. {i++;
  21. C[p]=i;
  22. if(p<k)Combinacii(p+1,i);
  23. else{for(int j =1;j<=k;j++)
  24. Z[j]=C[j];
  25. Permutacii(1);}
  26. }
  27. }
  28. bool Init()
  29. {
  30. cout<<"n=";cin>>n;
  31. if(n<2||n>10){cout<<"Error in n";return false;}
  32. cout<<"k=";cin>>k;
  33. if(k<2||k>=n){cout<<"Error in k";return false;}
  34. return true;
  35. }
  36. int main()
  37. {
  38. if(Init())
  39. {cout<<n<<" "<<k<<endl;
  40. Combinacii(1,0);}
  41. return 0;}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top