Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. void print(int tab[], int all)
  7. {
  8.     for(int i=0;i<=all;i++)
  9.         cout << tab[i];
  10.     cout << endl;
  11. }
  12.  
  13. void perm(int tab[], int act, int all)
  14. {
  15.     if(act==0)
  16.         print(tab,all);
  17.     else
  18.     {
  19.         for(int i=0;i<=act;i++)
  20.         {
  21.             swap(tab[i],tab[act]);
  22.             perm(tab,act-1,all);
  23.             swap(tab[i],tab[act]);
  24.         }
  25.     }
  26. }
  27.  
  28. int main()
  29. {
  30.     int n;
  31.     int tab[10];
  32.     cout << "Give a number to permute: " << endl;
  33.     cin >> n;
  34.  
  35.     for(int i=0;i<=n;i++)
  36.         tab[i]=i;
  37.  
  38.     perm(tab,n,n);
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement