MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / isPrime

Function isPrime

CPP/Maths/primeNo.cpp:4–21  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2using namespace std;
3
4bool isPrime(int n)
5{
6 if (n == 1)
7 return false;
8
9 if (n == 2 || n == 3)
10 return true;
11
12 if ((n % 2 == 0 )|| (n % 3) == 0)
13 return false;
14
15 for (int i = 5; i * i <= n; i = i + 6)
16 {
17 if ((n % i == 0) || (n % (i + 2) == 0))
18 return false;
19 }
20 return true;
21}
22
23int main()
24{

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected