Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int n;
  5. int arr[100], used[100];
  6.  
  7. void go(int index) {
  8. if (index == n) {
  9. for (int i = 0; i < n; i++) {
  10. printf("%d%c", arr[i], (i==n-1?'\n':' '));
  11. }
  12. return;
  13. }
  14.  
  15. for (int value=1; value<=n; value++) {
  16. if (used[value] == 0) {
  17. used[value] = 1;
  18. arr[index] = value;
  19. go(index+1);
  20. used[value] = 0;
  21. }
  22. }
  23. }
  24.  
  25. int main(void) {
  26. cin >> n;
  27. go(0);
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement