Created
August 7, 2016 01:11
-
-
Save grantmwilliams/270c9a8c6ec0692483b5eb1fcffdb611 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arr[10001] = {0} | |
count = 1; | |
arr[0] = 2; | |
num = 2; | |
bool is_prime; | |
while (count < 10001) // loop through all numbers | |
{ | |
num++; // starts with 3 | |
is_prime = true; // sets the number to prime unless we find otherwise | |
for (int num = 0; i < count; i++) | |
{ | |
if (arr[count] % num == 0) // num is not prime | |
{ | |
is_prime = false; | |
break; // break out of loop early | |
} | |
if (is_prime) | |
{ | |
count++; | |
arr[count] = num; // add to primes to check in future | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment