<1>方法一
//判断是否是一个素数
int IsPrime(int a){
//0,1,负数都是非素数
if(a <= 1){
return 0;
}
//计算枚举上界,为防止double值带来的精度损失,所以采用根号值取整后再加1,即宁愿多枚举一个,也不愿少枚举一个数
int bound = (int)sqrt(a) + 1;
for(int i = 2;i < bound;i++){
//依次枚举这些数能否整除x,若能则必不是素数
if(a % i == 0){
return 0;
}
}
return 1;
}
![](https://img-my.csdn.net/uploads/201303/19/1363701758_1530.jpg)
<2>方法二
#define MAXSIZE 10001
int Mark[MAXSIZE];