题目
输入一个数,判断是否是素数。
C代码
代码语言:javascript复制#include<stdio.h>
#include<math.h>
int judge(int num)
{
int i;
if(num<2)
return 0;
for(i=2;i<=sqrt(num);i )
if(num%i==0)
break;
if(i>sqrt(num))
return 1;
return 0;
}
int main()
{
int num;
scanf("%d",&num);
if(judge(num)==0)
printf("NOT");
else
printf("YES");
}
C 代码
代码语言:javascript复制#include<iostream>
#include<cmath>
using namespace std;
int judge(int num)
{
int i;
if(num<2)
return 0;
for(i=2;i<=sqrt(num);i )
if(num%i==0)
break;
if(i>sqrt(num))
return 1;
return 0;
}
int main()
{
int num;
cin>>num;
if(judge(num)==0)
cout<<"NOT";
else
cout<<"YES";
}