Category : Miscellaneous Language Source Code
Archive   : EUPHOR10.ZIP
Filename : SIEVE.C

 
Output of file : SIEVE.C contained in archive : EUPHOR10.ZIP
#define ITERATIONS 10000

#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);
}


  3 Responses to “Category : Miscellaneous Language Source Code
Archive   : EUPHOR10.ZIP
Filename : SIEVE.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. 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/