#include <stdio.h>
#include <math.h>
#define SIZE 100
int status[SIZE];
void sieve()
{
int i, j, sq;
for(i = 0; i < SIZE; i++) {
status[i] = 0;
}
sq = sqrt(SIZE);
for(i=4;i<=SIZE;i+=2) {
status[i] = 1;
}
for(i = 3; i <= sq; i += 2)
{
if(status[i] == 0){
for(j = 2*i; j <= SIZE; j += i)
status[j] = 1;
}
}
status[1] = 1;
}
int main(){
int i, counter = 100;
sieve();
printf("/nFollowing numbers are prime in the range: 1 to %d :/n", counter);
for (i = 1; i < counter; i++){
if(status[i]==0) {
printf("%d/t", i);
}
}
return 0;
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/266579.html