编写一函数IsPrime,判断某个大于2的正整数是否为素数。样例输入:
5
样例输出:
yes样例输入:
9
样例输出:
5
样例输出:
yes样例输入:
9
样例输出:
no注意:是素数输出yes,不是素数输出no,其中yes和no均为小写。
#include "stdio.h"
int IsPrime(int n)
{
int i ;
if(n==2)
{
return 1 ;
}
else
{
for(i=2;i<n;i++)
{
if(n%i==0)
{
return 0 ;
}
}
}
return 1 ;
}
int main()
{
int n ;
scanf("%d",&n);
if(IsPrime(n)==1)
{
printf("yes\n");
}
else
{
printf("no\n");
}
return 0 ;
}