summaryrefslogtreecommitdiffhomepage
path: root/examples/cbits_prime.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-03-29 14:27:14 +0200
committerTyge Løvset <[email protected]>2021-03-29 14:27:14 +0200
commitc8a7b59dcc8a1d6cd7bf5f5bc6b76f26a97b34d6 (patch)
treed2a3876500a66c5967acb8163b16c20c06e93ae4 /examples/cbits_prime.c
parent535af062240a244bb8397634ceec985e5a7f30ed (diff)
downloadSTC-modified-c8a7b59dcc8a1d6cd7bf5f5bc6b76f26a97b34d6.tar.gz
STC-modified-c8a7b59dcc8a1d6cd7bf5f5bc6b76f26a97b34d6.zip
Another update of cbits.
Diffstat (limited to 'examples/cbits_prime.c')
-rw-r--r--examples/cbits_prime.c39
1 files changed, 0 insertions, 39 deletions
diff --git a/examples/cbits_prime.c b/examples/cbits_prime.c
deleted file mode 100644
index e2e7877a..00000000
--- a/examples/cbits_prime.c
+++ /dev/null
@@ -1,39 +0,0 @@
-#include <stdio.h>
-#include <stc/cbits.h>
-
-static inline cbits sieveOfEratosthenes(size_t n)
-{
- cbits primes = cbits_with_size(n + 1, true);
- cbits_reset(&primes, 0);
- cbits_reset(&primes, 1);
-
- c_forrange (i, size_t, 2, n+1) {
- // If primes[i] is not changed, then it is a prime
- if (cbits_test(primes, i) && i*i <= n) {
- c_forrange (j, size_t, i*i, n+1, i) {
- cbits_reset(&primes, j);
- }
- }
- }
- return primes;
-}
-
-
-int main(void)
-{
- int n = 100000000;
- printf("computing prime numbers up to %u\n", n);
-
- cbits primes = sieveOfEratosthenes(n);
- puts("done");
-
- size_t np = cbits_count(primes);
- printf("number of primes: %zu\n", np);
-
- printf("2 ");
- c_forrange (i, int, 3, 1001, 2) {
- if (cbits_test(primes, i)) printf("%d ", i);
- }
- puts("");
- cbits_del(&primes);
-} \ No newline at end of file