From a4d6defa1722d52bf0f5bb2f3abf1443c4b6509c Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sat, 22 Nov 2025 15:34:30 +0100 Subject: Added talk --- src/talks/wasm/examples/4-primes-sieve/primes.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/talks/wasm/examples/4-primes-sieve/primes.c (limited to 'src/talks/wasm/examples/4-primes-sieve/primes.c') diff --git a/src/talks/wasm/examples/4-primes-sieve/primes.c b/src/talks/wasm/examples/4-primes-sieve/primes.c new file mode 100644 index 0000000..3f86864 --- /dev/null +++ b/src/talks/wasm/examples/4-primes-sieve/primes.c @@ -0,0 +1,23 @@ +#include +#include + +int count(int n) { + if (n < 2) + return 0; + + /* Prepare sieve array */ + char *notprime = malloc(n+2); + memset(notprime, 0, n+2); + + int count = 0; + for (int i = 2; i < n; i++) { + count += 1 - notprime[i]; + for (int j = 2*i; j < n; j += i) + notprime[j] = 1; + } + + /* Manual memory management is fun :D */ + free(notprime); + + return count; +} -- cgit v1.3