468,513 Members | 927 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,513 developers. It's quick & easy.

prime number or not

i have to determine the number entered by the user is a prime number or not. plz if you can tell me than reply.
Sep 13 '06 #1
1 3174
Banfa
9,056 Expert Mod 8TB
i have to determine the number entered by the user is a prime number or not. plz if you can tell me than reply.
A prime number is 1 that has no integer divisors other than 1 and itself.

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.
Sep 13 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

36 posts views Thread by Dag | last post: by
9 posts views Thread by Greg Brunet | last post: by
11 posts views Thread by lostinpython | last post: by
11 posts views Thread by don | last post: by
4 posts views Thread by SweetLeftFoot | last post: by
60 posts views Thread by rhle.freak | last post: by
7 posts views Thread by newstips6706 | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.