vector <int> arr (1,2);
bool isprime;
for (int c=3;c<50000;c++) // primes up to 5000
{
for (int m=0;m<arr.size();m++) // checks against previous primes
{
isprime =true;
if (c % arr[m] == 0) // if current number modulus any previous prime is 0 then not a prime
{
isprime =false;
break;
}
}
if (isprime) // if prime add to other primes to be checked.
{
arr.push_back (c);
cout << c<<endl;
}
}
If so could someone give me hints about how to make it faster?