both inner and outer loops are checking only within possible limits. the even numbers are not checked even once throughout the process. Why this code performs better than already accepted ones: Checkout the results for different N values in the end. Starting at 2, I would cross off 4, 6, 8, and 10. Using Sieve of Eratosthenes logic, I am able to achieve the same results with much faster speed. For example, if I wished to check for all the primes below 10, my first list would be 1,2,3,4,5,6,7,8,9,10.
How would I need to change this code to the way my book wants it to be? int main () So I did try changing my 2nd loop to for (int j=2 j
It mentions something about square root of a number. Continue like this till every number is either circled or crossed out. This c++ code prints out the following prime numbers: 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97.īut I don't think that's the way my book wants it to be written.