Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n;
- int arr[100], used[100];
- void go(int index) {
- if (index == n) {
- for (int i = 0; i < n; i++) {
- printf("%d%c", arr[i], (i==n-1?'\n':' '));
- }
- return;
- }
- for (int value=1; value<=n; value++) {
- if (used[value] == 0) {
- used[value] = 1;
- arr[index] = value;
- go(index+1);
- used[value] = 0;
- }
- }
- }
- int main(void) {
- cin >> n;
- go(0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement