I this post you will learn to write a C program without using recursive function to generate the permutation of a given array. The approach using recursive function is more simple and is easily available on internet. I tried this approach as I was not able to find any implementation of this approach on internet. If you don’t want any theory you may directly skip to the program in the last page or I will start with explaining my understating of permutation.

Lets consider you have the following array 1, 2, 3 The total permutation possible are as follows

Case 1 : Without repetition and with maximum fixed length
1 2 3 ~ 1 3 2 ~ 2 1 3 ~ 2 3 1 ~ 3 1 2 ~ 3 2 1
The number of permutation is given by the formula below
n * (n - 1) * (n - 2) * . . . * 1 = n!

Case 2 : With repetition and with maximum fixed length
1 1 1 ~ 1 1 2 ~ 1 1 3 ~ 1 2 1 ~ 1 2 2 ~ 1 2 3 ~ 1 3 1 ~ 1 3 2 ~ 1 3 3
2 1 1 ~ 2 1 2 ~ 2 1 3 ~ 2 2 1 ~ 2 2 2 ~ 2 2 3 ~ 2 3 1 ~ 2 3 2 ~ 2 3 3
3 1 1 ~ 3 1 2 ~ 3 1 3 ~ 3 2 1 ~ 3 2 2 ~ 3 2 3 ~ 3 3 1 ~ 3 3 2 ~ 3 3 3
The number of permutation is given by the formula n ^ n

Case 3 : Without repetition and with different length
1     ~ 2     ~ 3
1 2   ~ 1 3   ~ 2 1  ~ 2 3 ~ 3 1 ~ 3 2
1 2 3 ~ 1 3 2 ~ 2 1 3 ~ 2 3 1 ~ 3 1 2 ~ 3 2 1
The number of permutation is given by the formula below and implementation in Sample code 10.1

1 2 3