我是一个c++新手,求0—1000间的质数,程序错在哪?
#include<iostream>#include"math.h"
using namespace std;
int main()
{
int i,j,is_prime;
is_prime = true;
cout<<"We will print all prime along 2 and 1000:"<<endl;
for(i=2;i<=1000;i++)
{
for(j=2;j<=sqrt((double) i);j++)
{ if(i%j ==0)
is_prime =false;
if(is_prime)
cout<< i <<" "<<endl;
}
}
return 0;
}