编写一个函数,用于判断一个数是不是素数(特判0和1)
#include <bits/stdc++.h>
using namespace std;
int pan(int x)
{
int i;
if(x==0||x==1)//别忘了x为0或1时的特判
return 0;
else
for(i=2; i<=sqrt(x); i++)
if(x%i==0)
{
return 0;
}
return 1;
}
int main()
{
int x;
while(scanf("%d",&x)!=EOF)
{
int t=pan(x);
if(t)
printf("x是素数\n");
else
printf("x不是素数\n");
}
return 0;
}