Program that checks if a number is prime number

后端 未结 5 2335
情深已故
情深已故 2020-12-12 08:35

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

5条回答
  •  生来不讨喜
    2020-12-12 08:52

    If a number is prime, that means no number evenly divides it besides 1 and itself. That mean you need to check every number below it before being able to say the number is prime.

    In your code, you are exiting the loop on the first iteration -- regardless of how large the number is.

提交回复
热议问题