I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
get GPL
COST (GBP)
this unit 0.00
sub units 0.00
+
0

is prime

This function determines whether n is a prime number or not.
Controller: ideswa

Interface

C++

IsPrime

 
boolisPrimeintn )
This function looks for possible divisions, when one is found, it returns false, otherwise, it returns true.

Example

This example computes the first set of prime numbers:
#include <iostream>
#include <codecogs/maths/discrete/number_theory/is_prime.h>
int main(int argc, char **argv)
{
    for(unsigned int i = 2; i < UINT_MAX; i++)
    {
        if(isPrime(i))
            std::cout << i << std::endl;
    }
    return 0;
}
Output
2, 3, 5, 7, 11, 13, .......... until UINT_MAX!

Parameters

nInput number

Returns

True or false

Authors

Ide Swager
Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.