Algorithm to print all the number possible with the digits of a given number

eg :if input is "234",combinations possible are

234,243,324,342,432,423

+5 votes

Algorithm to print all the number possible with the digits of a given number

eg :if input is "234",combinations possible are

234,243,324,342,432,423

+5 votes

0 votes

Try this (in C++ though u can write it again in C)

```
#include <iostream>
#include <algorithm>
using namespace std;
void outputArray(int* array, int size)
{
for (int i = 0; i < size; ++i) { cout << array[i] << " "; }
}
int main ()
{
int myints[] = { 1, 2, 3, 4, 5 };
const int size = sizeof(myints);
cout << "The 5! possible permutations with 5 elements:\n";
sort (myints, myints + size);
bool hasMorePermutations = true;
do
{
outputArray(myints, size);
hasMorePermutations = next_permutation(myints, myints + size);
}
while (hasMorePermutations);
return 0;
}
```

...