I tried doing this with a for loop but my code is not working
int main()
{
int n,i=2;
cin>>n;
for(i=2;i<=n-1;i++)
{
if(n%i==0)
{
cout<<“Not Prime”<<endl;
break;
}
}
if (i==n)
cout<<"Prime"<<endl;
return 0;
}
please help
I tried doing this with a for loop but my code is not working
int main()
{
int n,i=2;
cin>>n;
for(i=2;i<=n-1;i++)
{
if(n%i==0)
{
cout<<“Not Prime”<<endl;
break;
}
}
if (i==n)
cout<<"Prime"<<endl;
return 0;
}
please help
Hey Anikash, you code is working fine, can you please mention what actual difficulty are you facing with this code.
I figured out the problem. Thank you!