Skip to content

Instantly share code, notes, and snippets.

@grantmwilliams
Created August 7, 2016 01:11
Show Gist options
  • Save grantmwilliams/270c9a8c6ec0692483b5eb1fcffdb611 to your computer and use it in GitHub Desktop.
Save grantmwilliams/270c9a8c6ec0692483b5eb1fcffdb611 to your computer and use it in GitHub Desktop.
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