Skip to content

Instantly share code, notes, and snippets.

@jdtech3
Created January 20, 2023 01:36
Show Gist options
  • Save jdtech3/51336244ce8421e6c18724eb7eaf5588 to your computer and use it in GitHub Desktop.
Save jdtech3/51336244ce8421e6c18724eb7eaf5588 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <math.h>
#define CHECK_UP_TO 100
int main() {
_Bool notPrime[CHECK_UP_TO] = { 1, 1 };
for (int i = 0; i < sqrt(CHECK_UP_TO); i++) {
if (notPrime[i] == 0) {
int j = 2 * i;
while (j < CHECK_UP_TO) {
notPrime[j] = 1;
j += i;
}
}
}
for (int i = 0; i < CHECK_UP_TO; i++) if (notPrime[i] == 0) printf("%d ", i); // print
return 0;
}
// sieve of eratosthenes implementation by jdtech3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment