Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- void perm(int *ch,int a,int b);
- int n;
- int c=0;
- int main()
- {
- cout << "enter a number you want to perm : "<<endl;
- cin >> n;
- int list[n];
- for(int i=0;i<n;i++)
- list[i] = i+1;
- perm(list,0,n-1);
- cout << c <<" type for " << n << " permutation"<<endl;
- system("pause");
- return 0;
- }
- void perm(int *ch,int a,int b)
- {
- if(a==b){
- for(int i=0;i<n;i++)
- cout << ch[i];
- cout << endl;
- c++;
- }
- else
- for(int j=a;j<n;j++){
- swap(ch[a],ch[j]);
- perm(ch,a+1,b);
- swap(ch[a],ch[j]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement