Category : Miscellaneous Language Source Code
Archive   : EUPHOR10.ZIP
Filename : SIEVE.C
#include
#include
#define SIZE 8190
#define ON 1
#define OFF 0
char flags[SIZE + 1];
SetBlock(var, size, val)
register char *var;
register int size;
register char val;
{
/*register*/ int i;
for (i = 0; i < size; i++)
var[i] = val;
}
main()
{
/*register*/ int count, i, k, prime;
int iter;
int t;
t = clock();
for (iter = 1; iter <= ITERATIONS; iter++) {
count = 0;
/* turn flags on (non-zero) */
SetBlock(flags, SIZE, ON);
for (i = 0; i <= SIZE; i++) {
if (flags[i]) {
prime = i + i + 3;
/* printf("%d ", prime); */
k = prime + i;
while(k <= SIZE) {
flags[k] = OFF;
k = k + prime;
}
count++;
}
}
}
printf("%d primes\n", count);
printf("%d iterations in %.2f seconds\n", ITERATIONS,
(clock() - t)/(double)CLOCKS_PER_SEC);
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/