Add sieve of eratosthenes

This commit is contained in:
Kevin Keogh
2019-03-18 15:20:29 -04:00
parent fe204db23c
commit 0551709888
2 changed files with 35 additions and 0 deletions

View File

@@ -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;