keil-C51-v6.12-完全解密版-17.8M.zip

源代码在线查看: sieve.c

软件大小: 11527 K
上传用户: a6810121
关键词: keil-C 17.8 6.12 zip
下载地址: 免注册下载 普通下载 VIP

相关代码

				/*------------------------------------------------------------------------------
				SIEVE.C:  Eratosthenes Sieve Prime Number Program in C from Byte Jan 1983.
				------------------------------------------------------------------------------*/
				
				#include 
				#include 
				#include 
				
				#define TRUE 1
				#define FALSE 0
				#define SIZE 8190
				
				char xdata flags[SIZE+1];
				
				/*------------------------------------------------
				------------------------------------------------*/
				void main (void)  {
				    register int i,k;
				    int prime,count,iter;
				
				/*------------------------------------------------
				Setup the serial port for 1200 baud at 16MHz.
				------------------------------------------------*/
				    SCON  = 0x50;                   	/* SCON: mode 1, 8-bit UART, enable rcvr    */
				    TMOD |= 0x20;                   	/* TMOD: timer 1, mode 2, 8-bit reload      */
				    TH1   = 221;                    	/* TH1:  reload value for 1200 baud @ 16MHz */
				    TR1   = 1;                      	/* TR1:  timer 1 run                        */
				    TI    = 1;                      	/* TI:   set TI to send first char of UART  */
				
				/*------------------------------------------------
				Th following code is an implementation of the 
				Sieve of Eratosthenes.
				------------------------------------------------*/
				    printf("10 iterations\n");
				    for (iter = 1; iter 				      {	
				        P1 = iter;                      /* output iter on P1 */
				
					count = 0;			/* initialize prime counter */
					for (i = 0; i 					  flags[i] = TRUE;
					for (i = 0; i 				        {
					    if (flags[i])		/* found a prime */
					      {
						prime = i + i + 3;	/* twice index + 3 */
						for (k = i + prime; k 						  flags[k] = FALSE;	/* kill all multiples */
						count++;		/* primes found */
					      }
					    }
				      }
				    printf("%d primes.\n",count);	/* primes found in 10th pass */
				
				    while (1);
				  }
				
				
							

相关资源