Listing 5.15 determines whether a number n is prime by checking whether 2, 3, 4, 5, 6,

Question:

Listing 5.15 determines whether a number n is prime by checking whether 2, 3, 4, 5, 6, ..., n/2 is a divisor. If a divisor is found, n is not prime. A more efficient approach is to check whether any of the prime numbers less than or equal to ?n can divide n evenly. If not, n is prime. Rewrite Listing 5.15 to display the first 50 prime numbers using this approach. You need to use an array to store the prime numbers and later use them to check whether they are possible divisors for n.

Listing

image

image

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: