*11111*
#include
int determine(int number) { int result = 1; int control; if (number == 1 || (number != 2 && number%2 == 0)) { result = 0; } else { for (control = 3;control<number;control+=2) { if (number %control == 0) { result = 0; break; } } }
return result;
}
int main (void) { int number; scanf("%d",&number); if (determine(number)) { printf("是素数"); } else { printf("不是素数"); }
return 0;
}
*22222222**
#include
int determine(int number) { int result = 1; int control; if (number == 1) result = 0; for (control =2;control <number;control++) { if (number %control == 0) { result = 0; break; } }
return result;
}
int main (void) { int number; scanf("%d",&number); if (determine(number)) { printf("是素数"); } else { printf("不是素数"); }
return 0;
} *333333**
#include
int main(void) { int number; scanf("%d",&number); int shuzu[number]; //数组初始为1,即都是素数 for (int control = 2;control < number;control++) { shuzu[control] = 1; } shuzu[1] = 0;//确定1为非素数 //找出非素数 int x = 2; while (x < number/2 ) { int a = 2; while (ax <number) { shuzu[ax] = 0; a++; } do { x++; } while ( shuzu[x] == 0); }
int count = 0;
for (int control = 1; control < number;control++) {
if (shuzu[control]) {
printf("%d",control);
count++;
if (count % 5 == 0) {
printf("\r");
} else {
printf("\t");
}
}
}
return 0;
}