title: Displaying nth row of Pascal's triangle
body: <p>I'm trying to create a program in c++ in which takes the users input and displays that specific row of Pascal's triangle. 
  i.e. inputting 3 should result in 1 3 3 1. 
  However when I input 3 in my program it displays "1 1 1 1". I think I'm fairly close but I can't quite work out what's wrong.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  int n, k, fact1, fact2, fact3, number1, number2, number3, nTakeAwayK, nChooseK;
  
  void CalculateNChooseK();
  
  int main()
  {
      cout &lt;&lt; "Enter a row number for Pascal's Triangle: ";
      cin &gt;&gt; n;
      int x = 1;
      for (int k = 0; k &lt;= n; k++)
      {
          cout &lt;&lt; x &lt;&lt; '\t';
          CalculateNChooseK();
          x = nChooseK;
  
      }
      cout &lt;&lt; endl;
      system("PAUSE");
      return 0;
  }
  
  void CalculateNChooseK()
  {
      fact1 = 1;
      for (number1 = 1; number1 &lt;= n; number1++)
      {
          fact1 = (fact1 * number1);
      }
  
      fact2 = 1;
      for (number2 = 1; number2 &lt;= k; number2++)
      {
          fact2 = (fact2 * number2);
      }
  
      nTakeAwayK = (n - k);
      fact3 = 1;
      for (number3 = 1; number3 &lt;= nTakeAwayK; number3++)
      {
          fact3 = (fact3 * number3);
      }
  
      nChooseK = fact1 / (fact2*fact3);
  }
  </code></pre>