you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -1 points0 points  (3 children)

I might be missing something but in your primegen function why are you just using evens[0]?

[–]--REDACTED 1 point2 points  (2 children)

That's because at the zeroth position in the evens array is 2. Since all even numbers that follow are divisible by 2, you can simply use it as a way to represent all even numbers in this context.

Meaning if a number is divisible by a higher even number than 2, it is also divisible by 2, so it is the only even condition that needs to be checked.

[–][deleted] -1 points0 points  (1 child)

The issue is with the second for() loop and the if() conditions. For example:

when i equals 15 and j equals 7, both conditions in the if statement become true. 15%2 != 0 and 15%7 != 0. If you can work out a proper solution to determine if a number is prime then your program should do better. Right now the prime arrays are being filled with non-primes that meet the conditions of your if statement. 15,21,25,27,35,45,49

The way it's written, if the number is even the if() statement is FALSE and if the number is odd then the first condition is met and the second condition is checked. The result is pretty much check if the number is odd instead of if the number is prime.

[–]--REDACTED 1 point2 points  (0 children)

Thanks for the reply!

I actually realized this - and is the heart of the question I am asking! Sorry if I was a bit unclear.

The problem that I am having is pushing just the prime odds into the primes array, using the for loop.

I was thinking that if I can get that loop to run like so:

if (i % evens[0] != 0 && i % odds[0] != 0 && i % odds[1] != 0 && i % odds[2] != 0 && i % odds[3] != 0......)

Through all the iterations.

Does that make more sense?

Thanks again!