用DEV-C++编写函数调用的判断素数的代码

来源:百度知道 编辑:UC知道 时间:2024/06/16 17:29:32
编写函数,从键盘输入一个整数x,并判别其是否是素数。并编写主函数对其调用。
以上,根据编写的代码是否符合要求(DEV-C++ 4.9.9.2能否运行为准),附加20~40分,信誉保证!

//---------------------------------------------------------------------------

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int isprm(int n)
{
int i;
for (i=2; i<=(int)floor(sqrt(n)); i++) {
if (n%i==0) {
return 0;
}
}
return 1;
}
int main(void)
{
int a;
scanf("%d",&a);
puts(isprm(a)?"YES":"NO");
system("pause");
return 0;
}
//---------------------------------------------------------------------------