Check prime . code is not correct

why its printing not only one time its repeating too much like prime not prime output is not clear please help and send me the right code also.

Hi @manishayadav1360_c0939b9a17f994ff,

You need to add a break statement after printing “prime” or “not prime” so that the controls come out of the for loop.

https://ide.codingblocks.com/s/653671 CHECK it Now it is not showing correct

@manishayadav1360_c0939b9a17f994ff,

tell me why you use bool here like what is purpose for that

Hi @manishayadav1360_c0939b9a17f994ff,

bool isPrime initially set to be true, is used to check whether the given number is prime or not.
Now we will be iterating over all possible divisors of n. If in any case for some i, n%i==0 then i is a factor of n.
Control will immediately break and come out of the for loop (in case of any divisor).

Lastly, we can check the state of isPrime and print accordingly.

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.