title: Code to print Nth prime number
body: <p>I have to print the Nth prime number.
  For example:<br/>
  <strong>1st prime number is 2<br/>
  2nd prime number is 3<br/>
  .<br/>
  .<br/>
  10th prime number is 29 and so on....</strong><br/></p>
  
  <p>My algorithm is as follows:<br/>
  1) Add 2 and 3 to stack. <br/>
  2) If n &lt;= Size of stack, get item at position n and output answer<br/>
  3) Else, start from last element of stack, check if prime<br/>
  4) To check for prime,  divide from each element in stack. If remainder 0 for any element in stack, not a prime. Break loop<br/>
  5) If Prime, add to stack<br/>
  6) Search only odd numbers<br/></p>
  
  <p>My code is :</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main() {
      int number, count = 0;
      cin &gt;&gt; number;          //position of prime number
      int a[number];
      a[0] = 2;
      a[1] = 3;
      int top = 1;
      if (number &lt;= 2) {
          cout &lt;&lt; a[number - 1] &lt;&lt; endl;
      } else {
          for (int i = 5; i &lt;= 10001; i += 2) {
              for (int j = 0; j &lt;= top; j++) {
  
                  if (i % a[j] != 0) {
                      count++;
  
                  }
                  if (count == (top + 1)) {
                      a[++top] = i;
                      if ((count + 1) == number) {
                          cout &lt;&lt; a[top];
                          break;
                      }
  
                  }
  
              }
  
          }
  
      }
      return 0;
  }
  </code></pre>
  
  <p><strong>This code abruptly stops working without giving any output.What is the flaw in my code?</strong></p>