Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 22 Online
OpenStudy (anonymous):

This question is for Problem Set 1 - Problem 1. I've already found how to generate all prime numbers, but how do I print just the 1000th one?

OpenStudy (e.mccormick):

Don't print each time. Just store it. Then, after finding it, print just that last result.

OpenStudy (harsimran_hs4):

you can do it the following ways : 1. if you don`t need the other prime numbers in your code , then you don`t need to store them all you need to do is keep a count of number of primes, when it reaches 1000 just print and exit 2. if you need the other prime numbers , then maybe store them in some form(arrays or list) and print the 1000 th prime for this problem

OpenStudy (anonymous):

@harsimran_hs4 Yes, I realized just a few minutes ago! That's what I wasn't doing, keeping a count. Thank you :)

OpenStudy (harsimran_hs4):

Welcome!!

OpenStudy (e.mccormick):

I didn't mean store all of them, just the one you are working on... which you do to find them.

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!
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!