Print all possible combination of numbers for entered number.

Please help me in solving a puzzle, whose description is give below. Just help me with the logic.

A user can input an array of any size. Where each element of the array is a single digit number. We have to display all the possible combinations for the entered array as the output.

Example

Input: array= 1 2 3

output: the various combinations are
1 2 3
3 1 2
2 3 1
3 2 1
1 3 2
2 1 3
Here there are 3 inputs “1 2 3” the logic should be able to do the above for n no of inputs.

It looks like you want to find all the permutations. Look this
link. It should help you to generate all permutations. You can also google for any other permutation generating algorithms like Johnson-Trotter etc