Created
July 7, 2019 07:30
-
-
Save youknowcast/dd40c499c5d25b5d8538a8112adb8c2e to your computer and use it in GitHub Desktop.
eratosthenes with Clang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
#define NUM 100000 | |
int main(void) { | |
int prime[NUM + 1]; | |
int i, j, Limit; | |
for (i=2; i <= NUM; i++) { | |
prime[i] = 1; | |
} | |
Limit = (int)sqrt((double)NUM); | |
for (i=2; i <= Limit; i++) { | |
if (prime[i] == 1) { | |
for (j=i*2; j <= NUM; j++) { | |
if (j % i == 0) { | |
prime[j] = 0; | |
} | |
} | |
} | |
} | |
for (i = 2; i <= NUM; i++ ) { | |
if (prime[i] == 1) { | |
printf("%d", i); | |
printf("\n"); | |
} | |
} | |
printf("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment