Megalextoria
Retro computing and gaming, sci-fi books, tv and movies and other geeky stuff.

Home » Archive » net.micro.cbm » Seive of Erasthones Correection
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Seive of Erasthones Correection [message #76156] Wed, 29 May 2013 23:44
Anonymous
Karma:
Originally posted by: stephenc@tektronix.UUCP (Stephen Coan )
Message-ID: <4017@tektronix.UUCP>
Date: Wed, 31-Oct-84 11:59:49 EST
Article-I.D.: tektroni.4017
Posted: Wed Oct 31 11:59:49 1984
Date-Received: Fri, 2-Nov-84 05:48:35 EST
Organization: Tektronix, Beaverton OR
Lines: 39

A recently posted article had a 'C' program for the Seive.  It appears that
the program was one that came from BYTE a few years ago.  The program is
fine for benchmarks, but is HORRIBLE as a real seive.  Take a look at the 
output, and you will see prime numbers such as 6242, etc.  A corrected
version of the program follows:

#define SIZE 8191

char flags[SIZE];

main()
{
	short i, prime, k, count;	/* short for portability */

	count = 0;
	for (i = 0; i < SIZE; i++)
		flags[i] = 1;
	for (i = 2; i < SIZE; i++)	{
		if (flags[i])	{
			prime = i;
			for (k = prime + prime; k < SIZE; k += prime)
				flags[k] = 0;
			count++;
			printf ("%d\n",prime);
		}
	}
	printf ("\n%d primes.\n", count);
}
The correct count when run is 1027 primes.
NOTE:  This does not have the 10 iterations included as the did the BYTE
article.  This can be added by those that wish to use it for benchmark
testing.  

	I hope that this will help to clear up some possible confusion that
was generated by the BYTE article since it was published.  Happy computing!

			The Novice Unix Hacker
			Stephen Coan
			tektronix!scargo!stephenc
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Additions to PLUS/4 Review
Next Topic: Disk problem
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Tue Apr 16 13:25:07 EDT 2024

Total time taken to generate the page: 0.02127 seconds