About the prime number program

I want to know about how to check given numb is prime or not. I understand problem bt i have some doubt which is this if n=1 then our condition fails because 1 is neitheR prime nor not prime

Hey @manoj2597 you are right, so if your value of n is equal to 1 then you can say it’s not prime.
Whereas for any other number, start your loop from 2 to n-1 and check if that number is divisible by any of the number between this loop, if it’s divisible then it’s not prime, but if not then it’s prime :slight_smile:

Yeah u r right but i m user and i want optimized code for it so n=1 is necessary for optimized code. Plz suggest how i do that it

For optimising run your for loop from 2 to square root of n. It’s more optimised version :slight_smile:

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.