Article 111 - Prime Number Generator

Generating prime numbers is vital in computer technology. A lot of effort has been put into researching optimal methods to compute prime numbers because of the numerous applications in computer security.

By definition, a prime number is a number whose positive divisors is itself and 1. No other divisors is possible.

For example, 3, 5, and 7 are prime numbers, so are 11, 13, and 17.

In one sense, prime numbers are never even numbers (except 2), as even numbers are evenly divisble by 2.

Other than the even number optimization, there is no known other guaranteed method for quickly checking a number if it is prime.

That brings us to the following algorithm.

Prime number generator algorithm.

void primeNumberGenerator(){
    unsigned int number;
    unsigned int divisor;
    int passed;

    for( number = 3; number > 2; number += 2 ){
        passed = 1;

        for( divisor = 2; divisor < number / 2; divisor++ ){
            if( number % divisor == 0 ){
                passed = 0;
                break;
            }
        }

        if( passed ){
            //print prime number
        }
    }
}

Comments (0)

Post a comment

  • Name:
  • Post:
  • Challenge:

Register or login to post comments easier.


Vantasy World Copyright 2011 - 2017. Vantasy World is a project developed by Vantasy Online. Privacy Policy.