# Thread: Find first 250 Prime Number

1. ## Find first 250 Prime Number

Hi Experts,

I want to write a 'C' program to find the first 250 prime numbers and store
them in an array and then print them out in columns on the screen.

Can someone give me the coding if you already have it.

Thanks.

Howard

2. God I love when a semester is starting. See the homework FAQ. Why would you even consider taking a C class if you have no interest?

3. Try implementing a solution; we will help you if you have any questions.

I guess, you know what the prime number is.

Cheers

4. Code:
`main(x,y){for(;x++;)for(y=2;x%y;)++y/x&&printf("%d\n",x);}`

5. Any number that is not prime, is evenly divisible by a prime number.

So, mark 2 as the first prime and try dividing all the following (odd) numbers from 3 upwards with the primes you have found so far. If it cannot be divided by any without remainder, add it to the list of primes.

Continue, until you have 250 primes in the list.

(Optimisation: you don't have to test-divide with all primes, but up to the square root of the value you are currently testing.)

Popular pages Recent additions