I'm looking for an algorithm in C to generate all possible variations with repetitons for set lenght and from n elements. for example if the lenght 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?