Blueteeth wrote:it gives me 7935 but this is wrong !
Yep, that would be wrong. You have `prime+=2' after you have already found a prime, so the final value is some prime plus two. You might also have an off-by-one problem (I'm not sure, but those are easy to make in this type of problem). The thing to do is change the program to find the 6th prime, which is easier to verify. Once it's working, change the number back to 1001.
Kybo Ren wrote:Is it because there are (is?) prime numbers before 3?
Well, his counter was initialized to 1, so that takes care of the 2.
I know 2 is prime, but I also remember my math teacher saying there was controversy over whether 1 was prime. Can you tell me if 1 is prime, Alvaro?
Modern math considers that 1 is not a prime. Traditionally it was considered a prime, but it has different enough properties that it's better to call it something else (it's called a
unit).