```c
#include <stdio.h>
int main(void)
{
int i, n;
printf("请输入一个数字: ");
scanf_s("%d", &n);
for (i = 2; i < n; i++)
if (n % i == 0)
break;
if (i < n)
printf("%d is divisible by %d\n", n, i);
else
printf("%d 是质数\n", n);
return 0;
}
还有一种:
#include <stdio.h>
int main(void)
{
int i, n;
printf("请输入一个数字: ");
scanf_s("%d", &n);
for (i = 2; i *i<= n; i++)
if (n % i == 0)
break;
if (i < n)
printf("%d is divisible by %d\n", n, i);
else
printf("%d 是质数\n", n);
return 0;
}
```
标签:return,int,质数,C语言,素数,判定,printf,main,scanf From: https://blog.51cto.com/u_16270759/7526548