Ask your own question, for FREE!
Computer Science 81 Online
OpenStudy (anonymous):

Best C++ Program to generate prime numbers. Best C++ Program to generate prime numbers. @Computer Science

OpenStudy (anonymous):

For any given candidate number, the smallest possible divisor is 2, and the largest possible divisor is (candidate / 2). So, for that range of divisors, check the result of (candidate % [modulo] divisor). If any result is zero, then the candidate is not a prime. If none of the divisor yield a zero modulo result, the candidate is a prime. Leave it to you to do your own coding of this algorithm. It's really quite simple.

OpenStudy (anonymous):

im ganna write it in c language which might help ya: all i understanf is that you wanna generate all possible prime numbers (and lets say from 0 to 1000) int count; int i; for(count=0;count<=1000;count ++) { int p=0; for(i=0;i<=count;i++) if(count % i ==0) p++; if(p==2) printf("count\t); }

OpenStudy (anonymous):

hope it will work....try it :D

OpenStudy (anonymous):

I read a webpage that said the best-performing algorithm was the Sieve of Eratosthenes. But it requires O(n) space, where n is the max prime you're looking for. A simpler way is to check divisors from 2 to sqrt(n). To optimize it a little more only test odd n's (ignore 2). To optimize more, only test odd divisors. To optimize more, only test prime divisors. To only test prime divisors, keep a list of primes that you find, and iterate over it when testing divisors (stop when you get to sqrt(n)).

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
rellhound: I lost my mom to suicide
2 hours ago 11 Replies 5 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!