C语言,自己写函数,判断一个数是不是素数,求改正哪错了#include <stdio.h>
#include<math.h>
int main()
{
int prime(int x);
int m;
printf("please input an integer number: ");
scanf("%d",&m);
if(prime(m))
printf("%d is a prime number.\n",m);
else
printf("%d is not a prime number.\n",m);
return 0;
}
int prime(int x)
{
int i,k;
k=sqrt(x);
for(i=2;i<=x;i++)
if(x%i!=0)
break;
else
return k;
}
é£å¤§ä½¬æè¿åºè¯¥æä¹æ¹
还是不对啊
追答int prime(int x)
{
int i,k;
k=sqrt(x);
for(i=2;i<=k;i++)
if(x%i==0) continue;
if(i==k+1) return 1;
else return 0;
}