Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ primality test

#include <iostream>
using namespace std;
bool isPrimeNumber(int n) {
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
  
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
  
    return true;
}
Source by www.tutorialspoint.com #
 
PREVIOUS NEXT
Tagged: #primality #test
ADD COMMENT
Topic
Name
2+9 =