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

29 lines
436 B
C

#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;
}