标签:space str iostream 判断 prim floor while break i++
输入一个数,判断是不是素数
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n,a;
while(cin>>n)
{
a=0;
if(n==2)
{
cout<<"is prime"<<endl;
continue;
}
if(n<=1)
{
cout<<"no is prime"<<endl;
continue;
}
int m=floor(sqrt(n)+0.5);
for(int i=2;i<=m;i++)
if(n%i==0)
{
cout<<"no is prime"<<endl;
a=1;
break;
}
if(a==0)
cout<<"is prime"<<endl;
}
return 0;
}
标签:space str iostream 判断 prim floor while break i++
原文地址:http://www.cnblogs.com/Aftersoon-sun/p/6274486.html