Klokova_Sofi

comb

Jan 17th, 2021
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int n, k;
  6. int arr[100];
  7.  
  8. void f(int p, int last) {
  9. if (p == k) {
  10. for (int i = 0; i < k; i++)
  11. cout << arr[i] << " ";
  12. cout << endl;
  13. return;
  14. }
  15. if (k - p > n - last)
  16. return;
  17. for (int i = last+1; i <= n; i++) {
  18. arr[p] = i;
  19. f(p+1, i);
  20. }
  21.  
  22. }
  23.  
  24. int main() {
  25. freopen("output.txt","w",stdout);
  26. cin >> n >> k;
  27. f(0, 0);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment