I'm looking for an algorithm in C to generate all possible variations with repetitions for set length and from n elements. For example, if the length is 3 and the elements are: 1, 2. The output should be :
1 1 1
1 1 0
1 0 0
1 0 1
0 0 0
0 0 1
0 1 1
0 1 0
I already looked for the solutions here, but all I could find were implementations in Java or Python and I don't know how to rewrite them to C. Can somebody please post a C code for this problem here?