mhdew

Permutation

Feb 1st, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. #include<stdio.h>
  2. int used[10000];
  3. int p[10000];
  4.  
  5. int par(int n, int pos)
  6. {
  7. int i, j;
  8. if(pos==n){
  9. for(j=0;j<n;j++)
  10. printf("%d ", p[j]);
  11. printf("\n");
  12. return;
  13. }
  14.  
  15. for(i=1;i<=n;i++){
  16. if(used[i]==0){
  17. used[i]=1;
  18. p[pos]=i;
  19. par(n,pos+1);
  20. used[i]=0;
  21. }
  22. }
  23. }
  24. int main()
  25. {
  26. int n;
  27.  
  28. scanf("%d", &n);
  29.  
  30. par(n,0);
  31.  
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment