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
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
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?
Try implementing a solution; we will help you if you have any questions.
I guess, you know what the prime number is.
Cheers
Code:main(x,y){for(;x++;)for(y=2;x%y;)++y/x&&printf("%d\n",x);}
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
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.)