( Index )
Month

Brief Information about the May 97 CSIG Meeting.

Sieve of Eratosthenes - Prime Numbers

The Tuesday night (3rd Tuesday) meeting will feature a discussion on the above topic. Code will be discussed and handed out on both a DOS benchmark version and a Windows graphical version written in C++ for the Generic Windows API. The programs may be compiled under Borland, Microsoft, etc. compilers. The "basic level" section of the meeting will discuss a 1 page version of the program.


//	SIEVE.C		B.ARNOLD	05-07-1997
//
//	An implementation of the "Sieve of Eratosthenes"
//	
//	Purpose:
//		1. Finds all prime numbers up to 16381
//		2. Very CPU intensive and suitable for a benchmark.
//
//	Reference:
//		Byte Magazine 9/81 & 1/83
//
//	Results:
//		7.8 milliseconds in 1983 for an IBM 3033 mainframe.
//		3000 seconds     in 1983 for some BASIC interpretors.
//		7.0 milliseconds in 1997 on my 486DX100. (This code).
//
//	Compiler:  BCC 4.5,  large model, no optimization.
//
//	Theory:
//	A "prime" number is one that is not divisible by any other number. 
//	In the Sieve of Erotosthenes method, all the integers (1,2,3,etc.)
//	up to a certain value are thought of as being placed on a list. 
//	First all the multiples of two are crossed out, leaving only odd
//	numbers.  Then all the multiples of three are crossed out, then
//	the multiples of four, and so on.  When this process is completed,
//	only prime numbers are left on the list, since those that are a
//	multiple of some other number have be crossed out.

#include <stdio.h>
#include <time.h>

#define PRIME_MAX 16381

int process(void);


int main(void)
    {
    time_t first, second;
    int i, loop;
    printf("Sieve of Eratosthenes - 1000 loops  (1 .. %d)\n",PRIME_MAX);
    first = time(NULL);  			// Gets system time
    
    for(loop=0; loop<1000; ++loop)
	{
	i = process();
	if (!(loop%20)) putchar('þ');	// show some activity
	}
    
    second = time(NULL);
    printf("\nThe total time is: %u seconds\n",(unsigned int)(second-first));
    printf("\n%d primes\n",i);
    return 0;
    }

Java J++ Version 1.00 Professional - Free Software

Through the generosity of Microsoft I have received several dozen copies of "Microsoft Java J++ Version 1.00 Professional " for distribution to ACGNJ members in the C++ User Group, the Java Study Group, etc. This WIN95 and WINNT development package consists of 50 Megs of tools and information on a CD. Also included is a 350 page book: "Learn Java Now" by Stephen Davis.


"Random Access" questions start at 7:30 Tuesday night.

SOURCE CODE

Source Code Files

For help, email me at b a r n o l d @ i e e e . o r g
Back to C++ Main Page