The purpose of this program is to run an infinite prime generator that won't stop unless I tell the console to stop. This is not a sieve of Eratosthenes; it stores prime numbers in an array and divides by those primes to check if they are prime. This allows me to avoid dividing by the multiple of all primes.
Are there any ways I could optimize this program? When I tried to look on the Internet it only gave me sieves, but that wouldn't work for me because those programs need to know a limit.
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main()
{
int l=0;
bool isprime;
vector<int>primes;
primes.push_back(2);
for (int nur = 3;nur!=0;nur+=2)
{
isprime = true;
for (int primecount=0 ;primes[primecount]<=sqrt(nur);primecount++)
{
if (nur % primes[primecount] == 0)
{
isprime = false;
break;
}
else if (primes[primecount]*primes[primecount]>nur)
{
cout<<nur<<endl;
break;
}
}
if (isprime)
{
cout << nur << endl;
primes.push_back(nur);
// l++;
}
}
cout<<"Finished"<<endl;
// cout<<primes[l];
return 0;
}