题目
输入一个数,判断是否是素数。
C代码
#include#includeint 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");elseprintf("YES");}
C++代码
#include#includeusing 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";elsecout<<"YES";}