#include<bits/stdc++.h>
using namespace std;
void print_perm(char str[],int k,int n)
{
if(k==n)
cout<<str<<endl;
else
{
for(int i=k;i<n;i++)
{
swap(str[k],str[i]);
print_perm(str,k+1,n);
swap(str[k],str[i]);
}
}
}
int main()
{
char str[20];
cout<<"Enter a string"<<endl;
cin>>str;
print_perm(str,0,strlen(str));
return 0;
}
using namespace std;
void print_perm(char str[],int k,int n)
{
if(k==n)
cout<<str<<endl;
else
{
for(int i=k;i<n;i++)
{
swap(str[k],str[i]);
print_perm(str,k+1,n);
swap(str[k],str[i]);
}
}
}
int main()
{
char str[20];
cout<<"Enter a string"<<endl;
cin>>str;
print_perm(str,0,strlen(str));
return 0;
}
Comments
Post a Comment