#include
#include
bool is_prime(int tar){//判断是否为素数
int i = 2;
while(i <= sqrt(float(tar))){
if(tar % i == 0)
return false;
i++;
}
return true;
}
int main(){
int count = 0;
for(int i = 2; i<999;i++){
if(is_prime(i)){
printf("%3d ", i);//因为2-999,最多三位,所以用3就足够了
count ++;
if((count)%5 == 0){
printf("\n");
}
}
}
return 0;
}
//December 08,2014 By 12052010 测试已通过
#include
#include
bool judge(int num){
for(int i=2;i<=sqrt(num);i++)
if(num%i==0)
return false;
return true;
}
int main(){
int total=0;
int num;
for(num=2;num<=999;num++){
if(judge(num)){
if(total++%5==0 ) printf("\n");
printf("%5d",num) ;
}
}
return 0;
}