#include <stdio.h>
#include <math.h>
int prime(int x)
{
int i,n;
if(x==1)return 0;
n=sqrt(x);
for(i=2;i<=n;i++)
if(x%i==0)return 0;
return 1;
}
int main()
{
int x;
int decide;
printf("please enter a number\n");
scanf("%d", &x);
decide = prime(x);
if(decide == 1)
{
printf("素数\n");
}
else
{
printf("不是素数\n");
}
return 0;
}
#include <math.h>
int prime(int x)
{
int i,n;
if(x==1)return 0;
n=sqrt(x);
for(i=2;i<=n;i++)
if(x%i==0)return 0;
return 1;
}
int main()
{
int x;
int decide;
printf("please enter a number\n");
scanf("%d", &x);
decide = prime(x);
if(decide == 1)
{
printf("素数\n");
}
else
{
printf("不是素数\n");
}
return 0;
}