Eratosthenes 筛选法 c语言 数组+指针实现
来源:互联网 发布:mac pro强制关机 编辑:程序博客网 时间:2024/06/06 13:10
#include<stdlib.h>
#include<stdio.h>
#define SIZE 1000
#define TRUE 1
#define FALSE 0
int main()
{
char sieve[ SIZE ];
char *sp;
int number;
/*
Set the entire sieve to TRUE
*/
for( sp = sieve; sp < &sieve[ SIZE ]; )
*sp++ = TRUE;
/*
process each number from 3 to as many as the sieve holds
*/
for( number =3; ;number +=2 ){
sp = &sieve[ 0 ] + ( number -3 )/2;
if( sp >= &sieve[ SIZE ] )
break;
/*
Now advance the pointer by multiples of the number and set each subsequent entry FALSE.
*/
while( sp += number, sp < &sieve[ SIZE ] )
*sp = FALSE;
}
/* Go through the entire sieve now and print the numbers corresponding to the locations that remain TRUE */
printf( "2/n" );
for( number =3,sp = &sieve[ 0 ];sp < &sieve[ SIZE ]; number += 2 ,sp++ ){
if( *sp )
printf( "%d/n",number );
}
return EXIT_SUCCESS;
}
- Eratosthenes 筛选法 c语言 数组+指针实现
- Eratosthenes筛选法(C语言版)
- 了解BitSet类并实现素数筛选--Eratosthenes筛选法
- Eratosthenes筛选法
- Eratosthenes筛选法
- Eratosthenes筛选法
- Sieve of Eratosthenes(埃拉托斯特尼素数筛选法)--java实现
- Eratosthenes筛选法计算质数
- C语言二分查找法(指针和数组实现)
- 素数筛选法-Eratosthenes筛法优化
- Eratosthenes筛选法求素数的算法
- Eratosthenes筛选法求素数的算法
- 每日一小练——Eratosthenes 筛选法
- 找素数的Eratosthenes算法(筛选法)
- Eratosthenes筛选法(C++版)
- Eratosthenes筛选法与欧拉筛选法
- Eratosthenes筛选法与欧拉筛选法(整理)
- c语言 数组 指针
- 用DELPHI操作EXCEL
- UML几种关系描述
- mysql 命令行
- Android模拟器入门
- MyEclipse中js文件包含中文时保存出错的解决方法
- Eratosthenes 筛选法 c语言 数组+指针实现
- asp显示前N个汉字
- 克隆db_name相同的数据库
- iPhone开发入门(一)
- SUSE linux eclipse tomcat6 java开发环境搭建
- java优化
- 实习
- 物化视图 on prebuilt table
- 25 great free resources for making charts