Skip to content

Instantly share code, notes, and snippets.

@youknowcast
Created July 7, 2019 07:30
Show Gist options
  • Save youknowcast/dd40c499c5d25b5d8538a8112adb8c2e to your computer and use it in GitHub Desktop.
Save youknowcast/dd40c499c5d25b5d8538a8112adb8c2e to your computer and use it in GitHub Desktop.
eratosthenes with Clang
#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