酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

c语言编写程序,从键盘输入一个整数n(n>1),判断n是否为素数,输出yes或no 输入格式: "%d" 输出格式: "yes\n" 、"no\n" 输入样例: 9↙ 输出样例: no↙ 输入样例: 11↙ 输出样例: yes↙

```c #include <stdio.h> int isPrime(int n) { if (n <= 1) { return 0; } for (int i = 2; i * i <= n; i++) { if (n % i == 0) { return 0; } } return 1; } int main() { int n; scanf("%d", &n); if (isPrime(n)) { printf("yes\n"); } else { printf("no\n"); } return 0; } ``` [2024-09-28 23:02:50 | AI写代码神器 | 146点数解答]

相关提问