title: C: Hofstadter Q sequence with recursion
body: <p>I've to write a C function that print on screen the first N elements of Hofstadter Q sequence by using recursion.</p>
  <p>Hofstadter Q sequence definition is:</p>
  <blockquote>
  <p>Q(1)=Q(2)=2</p>
  <p>Q(n)= Q(n-Q(n-1)) + Q(n-Q(n-2))</p>
  </blockquote>
  <p>My code should be ok, but I don't know where to put the printf to print the results.</p>
  <p>First numbers are: 1, 1, 2, 3, 3, 4, 5, 5, 6, 6, 6, 8, 8, 8, 10, 9, 10, 11, 11, 12, 12, 12, 12, 16, 14, 14, 16, 16, 16, 16, 20, 17, 17, 20, 21, 19, 20, 22, 21, 22, 23, 23, 24, 24, 24, 24, 24, 32, 24, 25, 30, 28, 26, 30, 30 etc.</p>
  <p>My code is actually:</p>
  <pre><code>#include &lt;stdio.h&gt;
  int hof(int n);
  
  int main()
  {
      int n;
      int flag;
  
      printf(&quot;How many elements to print: &quot;);
      scanf(&quot;%d&quot;,&amp;n);
  
      flag=hof(n);
  
      return 0;
  }
  
  int hof(int n) {
      int res;
  
      if (n &lt; 3) res = 1;
      else res=hof(n-(hof(n-1)))+hof(n-(hof(n-2)));
  
      return res;
  }
  </code></pre>
  <p>Thank you.</p>