This is the simplest way of doing this. You can take any number as input from user like 147 and it will print all permutations as:
111, 114, 117, 141, 144, 147, 171, 174, 177, 411, 414, 417, 441, 444, 447, 471, 474, 477, 711, 714, 717, 741, 744, 747, 771, 774, 777.
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
bool Search(int A[],int num,int length)
{
for(int i = 0;i<length;i++)
if(A[i] == num)
return 1;
return 0;
}
int main()
{
int n;
cout << "Please Enter a Number\n";
cin>>n;
int num = n, k = 1;
int count = 0;
while(num>0)
{
num/=10;
count++;
}
cout<<"The All Permutations of " <<n<<" are: "<<endl;
num = n;
int *A = new int[count];
for(int i = 0;i<count;i++)
{
A[i] = num%10;
num/=10;
}
int fact = pow(count,count);
int *Ar = new int[fact];
int *B = new int[count];
int value,number = 0;
for(int i = 0;i<fact;)
{
for(int j = 0;j<count;++j)
{
value = (rand()%count);
B[j] = value;
}
for(int k= 0;k<count;k++)
number = number + A[B[k]]*pow(10,k);
if(Search(Ar,number,fact) == 0)
{
cout<<k++<<". "<<number<<endl;
Ar[i] = number;
++i;
}
number = 0;
}
return 0;
}