Hello I have created this program to check if a number is a prime number. It works but for some reason says that 999 is a prime number. Where is my mistake. It would be grea
you are checking for the 1st iteration only. Irrespective of whether it is prime or not it exits from the loop since one of the section i.e either 'if' or 'else' will execute causing the loop to break. The logic would be to check for the entire range of numbers from 2 to (number/2) and if it divides the number at some point it will not be a prime number. If the loop exits after iterating over the entire loop then it is a prime number. Hope you will be able to do it now. Thanks!.