Hey everyone, I need some help with this homework assignment. I have to write a program that prints all of the prime numbers from 2 to 100,000 and prints the number of primes between 2 and 100,000. I got my code to print all of the primes but I have no idea how to count the number of primes that were printed. Is there some sort of counter that I need?
//Lists prime numbers under 100,000:
int p;
for (int i=2; i<100000; i++)
{
if (p<i)
{
p=i;
}
bool prime=true;
for (int x=2; x*x<=i; x++)
{
if (i % x == 0)
{
prime=false;
break;
}
}
if(prime) cout << i << " ";
}
cout << p << endl;