2 * Calculate all primes up to a specific number.
15 /*****************************************************************************/
17 /*****************************************************************************/
21 #define COUNT 8192 /* Up to what number? */
22 #define SQRT_COUNT 91 /* Sqrt of COUNT */
24 static unsigned char Sieve[COUNT];
28 /*****************************************************************************/
30 /*****************************************************************************/
34 #pragma staticlocals(1);
38 static char ReadUpperKey (void)
39 /* Read a key from console, convert to upper case and return */
41 return toupper (cgetc ());
53 /* This is an example where register variables make sense */
54 register unsigned char* S;
59 printf ("Sieve benchmark - calculating primes\n");
60 printf ("between 2 and %u\n", COUNT);
61 printf ("Please wait patiently ...\n");
66 /* Execute the sieve */
68 while (I < SQRT_COUNT) {
70 /* Prime number - mark multiples */
81 /* Calculate the time used */
82 Ticks = clock() - Ticks;
83 Sec = (unsigned) (Ticks / CLOCKS_PER_SEC);
84 Milli = ((Ticks % CLOCKS_PER_SEC) * 1000) / CLOCKS_PER_SEC;
86 /* Print the time used */
87 printf ("Time used: %u.%03u seconds\n", Sec, Milli);
88 printf ("Q to quit, any other key for list\n");
90 /* Wait for a key and print the list if not 'Q' */
91 if (ReadUpperKey () != 'Q') {
92 /* Print the result */
94 for (I = 2; I < COUNT; ++I) {
98 printf ("Q to quit, any other key continues\n");
99 if (ReadUpperKey () == 'Q') {
105 if (kbhit() && ReadUpperKey == 'Q') {