FUNCTION
is_prime
This function determines whether n is a prime number or not.
You're viewing an older version of this page (#628). View the current version.
Interface
#include <codecogs/maths/discrete/number_theory/is_prime.h>
using namespace Maths::Discrete::Number_Theory;
This function looks for possible divisions, when one is found, it returns false, otherwise, it returns true.
Example 1
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
n
Input number
Returns
True or false
Interactive Calculator
n
Result
Computing…
Set a range above first to export a graph.
This function's source code is only visible to registered users — documentation and the calculator above are free to use either way. Sign in to see it.