Improve error handling
Added error handling in case of memory allocation error for problems 35, 46, 47, 49 and 50.
This commit is contained in:
parent
7f64f15e89
commit
846cb06c90
6
C/p035.c
6
C/p035.c
@ -18,7 +18,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;
|
||||
}
|
||||
|
||||
for(i = 101; i < 1000000; i += 2)
|
||||
{
|
||||
|
6
C/p046.c
6
C/p046.c
@ -18,7 +18,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;
|
||||
}
|
||||
|
||||
for(i = 3; !found && i < N; i += 2)
|
||||
{
|
||||
|
6
C/p047.c
6
C/p047.c
@ -18,7 +18,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;
|
||||
}
|
||||
|
||||
for(i = 645; !found && i < N - 3; i++)
|
||||
{
|
||||
|
6
C/p049.c
6
C/p049.c
@ -18,7 +18,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;
|
||||
}
|
||||
|
||||
for(i = 1489; i < N && !found; i++)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user