Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- const int N = 10;
- int n;
- bool used[N];
- int m[N];
- void rec(int pos)
- {
- if(pos == n)
- {
- for(int i = 0 ; i < n ; ++i)
- {
- printf("%d ",m[i]);
- }
- puts("");
- return;
- }
- for(int i = 1 ; i <= n ; ++i)
- {
- if(!used[i])
- {
- used[i] = true;
- m[pos] = i;
- rec(pos+1);
- m[pos] = -1;
- used[i] = false;
- }
- }
- return;
- }
- signed main()
- {
- scanf("%d",&n);
- rec(0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement