title: Calculating Fibonacci Numbers Recursively in C
body: <p>I'm trying to learn C by writing a simple program to output Fibonacci numbers. It isn't working.</p>
  
  <p><strong>fibonacci.h</strong></p>
  
  <pre><code>unsigned int fibonacci_recursive(unsigned int n);
  </code></pre>
  
  <p><strong>fibonacci.c</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "fibonacci.h"
  
  main() {
      unsigned int i;
      for (i = 0; i &lt; 10; i++) {
          printf("%d\t%n", fibonacci_recursive(i));
      }
      getchar();
  }
  </code></pre>
  
  <p><strong>fibonacci_recursive.c</strong></p>
  
  <pre><code>unsigned int fib_rec(unsigned int n);
  
  main(unsigned int n) {
       return fib_rec(n);
  }
  
  unsigned int fib_rec(unsigned int n) {
      if (n == 0) {
          return 0;
       } 
       if (n == 1) {
             return 1;
       }
       return fib_rec(n - 1) + fib_rec(n - 2);
  }
  </code></pre>
  
  <p>This is the error message VS 2010 gives me when I try to build the project:</p>
  
  <pre><code>1&gt;ClCompile:
  1&gt;  fibonacci_recursive.c
  1&gt;fibonacci_recursive.obj : error LNK2005: _main already defined in fibonacci.obj
  1&gt;fibonacci.obj : error LNK2019: unresolved external symbol _fibonacci_recursive referenced in function _main
  1&gt;c:\users\odp\documents\visual studio 2010\Projects\Fibonacci\Debug\Fibonacci.exe : fatal error LNK1120: 1 unresolved externals
  1&gt;
  1&gt;Build FAILED.
  1&gt;
  </code></pre>
  
  <p>What am I doing wrong here? Thanks for helping someone new to C.</p>