- /*检验一个数是不是质数*/
- #include<iostream.h>
- #include<math.h>
- void main()
- {
- long int a,b(2),c(0);
- cin>>a;
- double d=sqrt(a);
- switch (a)
- {
- case 2:
- case 3:
- case 5: c=1;
- default: if((a%2==1)&&(a%5!=0))
- {for(;b<=d;b++)
- {
- if(a%b==0){c=0;break;}
- c=1;
- }
- }
- }
- cout<<(c==0?"否":"是")<<endl;
- }
- //该片段来自于http://www.codesnippet.cn/detail/1007201513070.html
来源: http://www.codesnippet.cn/detail/1007201513070.html