Created
January 20, 2023 01:36
-
-
Save jdtech3/51336244ce8421e6c18724eb7eaf5588 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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