1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-12-03 17:26:21 +00:00
202401-programming-assignments/【实践课外】4.循环结构1/7-2 判断一个整数是否为素数.c

29 lines
436 B
C
Raw Normal View History

2024-10-25 08:43:54 +00:00
#include <stdio.h>
int main() {
int x;
scanf("%d", &x);
if (x <= 1) {
printf("No\n");
} else {
int is_prime = 1;
for (int i = 2; i <= x / i; i++) {
if (x % i == 0) {
is_prime = 0;
break;
}
}
if (is_prime == 1) {
printf("Yes\n");
} else {
printf("No\n");
}
}
return 0;
}