title: How to print out all the permutation of a range of numbers in C using recursion?
body: <p>I am trying to make a recursive function that would print out all the permutations with duplicates of an array of integers, but the numbers have a range, and the array size ranges as well. Say we have an array <code>num[2]</code> and it has a range from 0-1 for example, it would print out something like </p>
  
  <pre><code>00
  01
  11
  10
  </code></pre>
  
  <p>If it were a simple permutation I could use a simple permutation function like this: </p>
  
  <pre><code>void permute(int *array,int i,int length) { 
    if (length == i){
       printArray(array,length);
       return;
    }
    int j = i;
    for (j = i; j &lt; length; j++) { 
       swap(array+i,array+j);
       permute(array,i+1,length);
       swap(array+i,array+j);
    }
    return;
  }
  
  void swap(char *x, char *y)
  {
      char temp;
      temp = *x;
      *x = *y;
      *y = temp;
  }
  </code></pre>
  
  <p>but how do I make it go through a range of numbers of say n size with the given size of the array?</p>
  
  <p>My question is different to another one here as I do not have a set array with what the values are, the example code does that but what I need is help with making print all the permutation of range n in an array of k spots, so say that n is 3  and k is 3 then it would be </p>
  
  <pre><code>000
  001
  002
  003
  010
  011
  etc...
  </code></pre>