answersLogoWhite

0

A Prime number is a number that has no factors other than 1 and itself. For instance, 1, 2 and 3 are prime numbers. However, 4 isn't because it can also be divided evenly by 2.

Although a complicated floating-point function can be written to test if the division of a number is even, the C modulus operator (%) is far quicker. If 'n' modulus 'm' is zero, then the division is even - there is no fractional component.

Using this rule, the pseudo-code for testing if a number is prime is as follows:

- if number is zero, return false

- if number is less than 4, return true since 1, 2 and 3 are primes

- iterate a variable 'c' from 2 until the number 'n' minus 1

- if n modulus c is zero, return false, since 'n' has 'c' as a factor

- return true

All that remains is converting the above code to C (or any other programming language) using inline code or a function.

User Avatar

Wiki User

12y ago

What else can I help you with?