title: Homework-C Programming- Recursive Program
body: <p>Hey guys! I was assigned this program which was pretty simple and didn't take long to code, yet I can't get it to run. Nothing prints and I think it's because it goes into an endless loop. Just looking for a fix on this.</p>
  
  <p>Assignment:</p>
  
  <blockquote>
    <p>Write and test a recursive function
    that returns the value of the
    following recursive definition:</p>
  
  <pre><code>f(x) = 0        if x &lt;= 0 
  f(x- 1) + 2       otherwise
  </code></pre>
  </blockquote>
  
  <p>My program:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int main(void)
  {
      int n, x;
  
      int factorial(int n) {
  
          if (x &lt;= 0) {
              printf("x equals: ");
              return 1;
          } else {
              return n * factorial(n - 1); //error here
          }
          f(x) = f(x - 1) + 2;
      }
      return 0;
  }
  </code></pre>