title: C# Finding the Nth prime number
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3285562/prime-number-formula">Prime Number Formula</a>  </p>
  </blockquote>
  
  
  
  <p>I am trying to write some code in c# that will give me the nth prime number but once my code gets past 121 as a prime number it starts giving me incorrect numbers back.</p>
  
  <p>Now this could be that i have based my code off the wrong algorithm but i wanted to ask here and see if there is something i have done wrong.</p>
  
  <p>the code ask for nth prime 10001 - output: 43751 (which i know is wrong)</p>
  
  <p>Any where here is my code.</p>
  
  <pre><code>int[] p;
  int x = 0;
  p = new int[10002];
  for (int i = 0; i &lt; 1000000; i++)
  if (i % 2 != 0)
  {
      if (i % 3 != 0)
      {
          if (i % 5 != 0)
          {
              if (i % 7 != 0)
              {
                  p[x] = i;
                  x++;
                  if (x == 10001)
                  {
                      Console.WriteLine("{0}", i);
                      break;
                  }
              }
          }
      }
  }
  </code></pre>