title: Calculate factorial in C# using recursion
body: <p>I know how to calculate a factorial using a loop. Below is the code for loop, but I am getting an error while doing it by recursion. Below are both the code samples. How can I fix this?</p>
  
  <pre><code>namespace factorial
  {
      class Program
      {
          static void Main(string[] args)
          {
              int i, number, fact;
              Console.WriteLine("Enter the Number");
              number = int.Parse(Console.ReadLine());
              fact = number;
              for (i = number - 1; i &gt;= 1; i--)
              {
                  fact = fact * i;
              }
              Console.WriteLine("\nFactorial of Given Number is: "+fact);
              Console.ReadLine();
          }
      }
  }
  </code></pre>
  
  <p>Factorial using recursion:</p>
  
  <p>Is there something as where I am going wrong? When am I calculating it using recursion?</p>
  
  <p>Factorial using loop:</p>
  
  <pre><code>public double factorial_Recursion(int number)
  {
      if (number == 1)
          return 1;
      else
          return number * factorial_recursion(number - 1);
  }
  
  public double factorial_WhileLoop(int number)
  {
      double result = 1;
      while (number != 1)
      {
          result = result * number;
      }
      return result;
  }
  </code></pre>