Code isn't working for printing the prime numbers between a given range

#include
using namespace std;
int main()
{
int n,i,a,b;
cout<<“enter the range of numbers”;
cin>>a>>b;

for(i=a;i<=b;i++)
{
    for(n=2;n<=i/2;n++)
    {

    if(i%n==0)
    {
    break;
    }
    }
    if(i==n)
    {
        cout<<n<<endl;
    }

}
return 0;

}

hello @ramitkapoor

here use n<i

thank you, it’s working now but I still don’t get it, why isn’t it working for i/2?

for this codition loop will stop as soon as n wll be i/2+1

and because of that the if statement written below it will never execute

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.