Add sieve of eratosthenes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "primes.h"
|
||||
|
||||
#define MAX_NUM 100000000
|
||||
@@ -13,6 +14,7 @@ int main(int argc, char **argv)
|
||||
long sum = 0;
|
||||
char *primes;
|
||||
|
||||
/*
|
||||
primes = malloc((MAX_NUM+1)*sizeof(char));
|
||||
for (i=1; i<MAX_NUM+1; i++) {
|
||||
if (is_prime(i)) {
|
||||
@@ -21,6 +23,12 @@ int main(int argc, char **argv)
|
||||
primes[i] = FALSE;
|
||||
}
|
||||
}
|
||||
*/
|
||||
primes = eratosthenes(MAX_NUM);
|
||||
if (primes == NULL) {
|
||||
printf("Error");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for(i=1; i<MAX_NUM; i++) {
|
||||
match = TRUE;
|
||||
|
||||
Reference in New Issue
Block a user