Improve code

This commit is contained in:
2019-09-28 11:32:21 +02:00
parent 7489196be8
commit ec1d1fa446
8 changed files with 16 additions and 26 deletions

View File

@ -30,7 +30,11 @@ int main(int argc, char **argv)
clock_gettime(CLOCK_MONOTONIC, &start);
/* N set to 1000000 as a reasonable limit, which turns out to be enough.*/
primes = sieve(N);
if((primes = sieve(N)) == NULL)
{
fprintf(stderr, "Error! Sieve function returned NULL\n");
return 1;
}
/* Checking only odd numbers with at least 4 digits.*/
for(i = 1001; i < N; i += 2)

View File

@ -24,7 +24,11 @@ int main(int argc, char **argv)
clock_gettime(CLOCK_MONOTONIC, &start);
primes = sieve(N);
if((primes = sieve(N)) == NULL)
{
fprintf(stderr, "Error! Sieve function returned NULL\n");
return 1;
}
/* Straightforward brute force approach.*/
for(p1 = 3; p1 < N && !found; p1 += 2)