i have to determine the number entered by the user is a prime number or not. plz if you can tell me than reply.
prime number or not
Collapse
X
-
A prime number is 1 that has no integer divisors other than 1 and itself.Originally posted by shahrukhi have to determine the number entered by the user is a prime number or not. plz if you can tell me than reply.
Once they have entered the number all you have to do is test that number to see if has any integer divisors other than 1 and itself.
Start a loop with an initial value of 2 and an initial maximum of the number.
Check to see if the number is exactly divisible by the loop control using % operator (number % control == 0), if it is the number is not prime
If the number is not prime then set your maximum to number / control. This will reduce the number of values you have to check.
If the loop ends without detecting the the number is not prime then the number is prime.
Comment