//判断一个数是否为素数方法1
#include
int main()
{
int x = 0;
printf("Please input x(x>0):");
scanf("%d",&x);
for(int i=2;i
int func(int m)
{
if (m==2) {
return 1;
}
if (m%2==0) {
return 0;
}
for (int i=3;i<=m/2;i+=2)
{
if (m%i==0)
{
return 0;
}
}
return 1;
}
int main()
{
int x = 0;
printf("Please input x(x>0):");
scanf("%d",&x);
if (func(x))
{
printf("x=%d是一个素数
",x);
}
else
printf("x=%d不是素数
",x);
return 0;
}