The easiest way to find primes (and one we use for our students) is the Eratosthenes Seive.
Information on it can be found here:
http://ccins.camosun.bc.ca/~jbritton/jberatosthenes.htm
A tip: use a binary array to store the numbers. The index of the array is the number you want to identify as prime/non-prime, and the binary value of array[index] is whether or not the index is prime.