Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- void print(int tab[], int all)
- {
- for(int i=0;i<=all;i++)
- cout << tab[i];
- cout << endl;
- }
- void perm(int tab[], int act, int all)
- {
- if(act==0)
- print(tab,all);
- else
- {
- for(int i=0;i<=act;i++)
- {
- swap(tab[i],tab[act]);
- perm(tab,act-1,all);
- swap(tab[i],tab[act]);
- }
- }
- }
- int main()
- {
- int n;
- int tab[10];
- cout << "Give a number to permute: " << endl;
- cin >> n;
- for(int i=0;i<=n;i++)
- tab[i]=i;
- perm(tab,n,n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement