Finding all prime numbers between two numbers

closed account (EAXiz8AR)
So I have to input two numbers between 4 and 1 million and find out all the prime numbers between the two but I need some help...

Here is the computational part, if you could let me know how to get it right, that would be great!

The code keeps outputting numbers like 9 and 15, which I don't want


1
2
3
4
5
6
7
8
9
10
11
for (int i = b; i <= a; i++)
{
   for (int j = 2; j <= sqrt(i); j++)
   {
      if (i%j != 0 && i%2 != 0)
      {
         cout << i << " is prime" << endl;
      }
   }
}
Last edited on
Topic archived. No new replies allowed.