I\'ve got an issue with an assignment that I have requiring the use of arrays. I need to create the Sieve of Eratosthenes algorithm and print out all the prime numbers. I\'m
Here:
for(int n = 2; y < 1000; n++){
y = n * x;
numbers[y] = false;
}
you first check that y < 1000
, and then intialize and use it. This is the wrong way around.
Also, you can get away with running the above loop only when x
is prime. This won't affect correctness, but should make your code much faster.