fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int n, k, a[10], d = 1;
  5.  
  6. void pr() {
  7. cout << d << ": ";
  8. for (int i = 0; i < k; i++)
  9. cout << a[i] << " ";
  10. cout << endl;
  11. d++;
  12. }
  13.  
  14. void choose(int i, int start) {
  15. for (int j = start; j <= n; j++) {
  16. a[i] = j;
  17. if (i == k - 1)
  18. pr();
  19. else
  20. choose(i + 1, j + 1);
  21. }
  22. }
  23.  
  24. int main() {
  25. cin >> n >> k;
  26. choose(0, 1);
  27. }
  28.  
Success #stdin #stdout 0s 5288KB
stdin
5 3
stdout
1: 1 2 3 
2: 1 2 4 
3: 1 2 5 
4: 1 3 4 
5: 1 3 5 
6: 1 4 5 
7: 2 3 4 
8: 2 3 5 
9: 2 4 5 
10: 3 4 5