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?
Don't print each time. Just store it. Then, after finding it, print just that last result.
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
@harsimran_hs4 Yes, I realized just a few minutes ago! That's what I wasn't doing, keeping a count. Thank you :)
Welcome!!
I didn't mean store all of them, just the one you are working on... which you do to find them.
Join our real-time social learning platform and learn together with your friends!