Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n, k;
- int a[100];
- bool select[100];
- void print(int a[], int n) {
- cout << endl;
- for (int i = 1; i <= n; ++i)
- cout << a[i] << " ";
- }
- void list(int k, int pos) {
- for (int i = 1; i <= n; ++i) {
- if (!select[i]) {
- a[pos] = i;
- select[i] = true;
- if (pos == k) print(a, k);
- else list(k, pos + 1);
- select[i] = false;
- }
- }
- }
- int main()
- {
- cout << "n = "; cin >> n;
- cout << "k = "; cin >> k;
- for (int i = 1; i <= k; ++i) select[i] = false;
- list(k, 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement