summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/prime.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-02-12 22:47:55 +0100
committerTyge Løvset <[email protected]>2023-02-12 23:20:18 +0100
commit7dc6fddc079f4f572c8fb7c0ffd5a27e03291a2d (patch)
tree681d1894d917bc2fe244375298ea40f736c18e18 /misc/examples/prime.c
parent9904a7ea36f9e4f45d7e41e409ed23ad22821e8a (diff)
downloadSTC-modified-7dc6fddc079f4f572c8fb7c0ffd5a27e03291a2d.tar.gz
STC-modified-7dc6fddc079f4f572c8fb7c0ffd5a27e03291a2d.zip
Fairly large update before release 4.1, cleaning up docs and some minor additions.
Diffstat (limited to 'misc/examples/prime.c')
-rw-r--r--misc/examples/prime.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/misc/examples/prime.c b/misc/examples/prime.c
index 4a3b8498..1a272e78 100644
--- a/misc/examples/prime.c
+++ b/misc/examples/prime.c
@@ -27,20 +27,19 @@ cbits sieveOfEratosthenes(intptr_t n)
int main(void)
{
intptr_t n = 1000000000;
- printf("computing prime numbers up to %" c_ZI "\n", n);
+ printf("Computing prime numbers up to %" c_ZI "\n", n);
clock_t t1 = clock();
c_with (cbits primes = sieveOfEratosthenes(n + 1), cbits_drop(&primes)) {
- puts("done");
intptr_t np = cbits_count(&primes);
clock_t t2 = clock();
- printf("number of primes: %" c_ZI ", time: %f\n", np, (float)(t2 - t1) / (float)CLOCKS_PER_SEC);
+ printf("Number of primes: %" c_ZI ", time: %f\n\n", np, (float)(t2 - t1) / (float)CLOCKS_PER_SEC);
puts("Show all the primes in the range [2, 1000):");
printf("2");
c_forrange (i, 3, 1000, 2)
if (cbits_test(&primes, i>>1)) printf(" %lld", i);
- puts("");
+ puts("\n");
puts("Show the last 50 primes using a temporary crange generator:");
crange R = crange_make(n - 1, 0, -2);
@@ -48,7 +47,7 @@ int main(void)
, cbits_test(&primes, *i.ref>>1)
, c_flt_take(i, 50)) {
printf("%lld ", *i.ref);
- if (i.count % 10 == 0) puts("");
+ if (c_flt_last(i) % 10 == 0) puts("");
}
}
}