为什么不可以多次循环判断素数,刚开始可以判断,但次数多就不可以了?
#include<iostream>#include<cmath>
using namespace std;
int main()
{
int m,n,i;
char flag=1;
cout<<"Please enter the number :\n";
cin>>n;
if(n>0)
m=int (sqrt(n));
while(n!=1)
{
for(i=2;i<=m;i++)
{
if(n%i==0)
{
flag=0;
}
}
if(flag==0)
cout<<"The number is not prime\n";
else
cout<<n<<" :It is prime:"<<endl;
cin>>n;
}
return 0;
}