teng125
- 416
- 0
can smby give me a simple example algorithm to determine whether the number is prime or not such as using while loop, if...then...else or others which is simple
thanx
thanx
How many of those google hits did you actually look through?teng125 said:but I'm looking for a simple example about prime number determination [algorithm] for programming language only using if...then... or while loop or repeat loops... that describe the steps of calculation
buddyholly9999 said:A simple example I can think of is go through every integer between 1 and the prime number you want to test and check to see if it is a divisor.
a_ramage_1989 said:you only need to go up to a third of the number. This is because if it is even then you know it is not prime, unless it is two. odd numbers are not divisble by 2, so the next divisor would be 3.