summaryrefslogtreecommitdiff
path: root/graphs/cpp/is_prime
diff options
context:
space:
mode:
Diffstat (limited to 'graphs/cpp/is_prime')
-rw-r--r--graphs/cpp/is_prime/is_prime.hh5
-rw-r--r--graphs/cpp/is_prime/is_prime.hxx21
2 files changed, 26 insertions, 0 deletions
diff --git a/graphs/cpp/is_prime/is_prime.hh b/graphs/cpp/is_prime/is_prime.hh
new file mode 100644
index 0000000..ae83249
--- /dev/null
+++ b/graphs/cpp/is_prime/is_prime.hh
@@ -0,0 +1,5 @@
+#pragma once
+
+constexpr bool is_prime(unsigned n);
+
+#include "is_prime.hxx" \ No newline at end of file
diff --git a/graphs/cpp/is_prime/is_prime.hxx b/graphs/cpp/is_prime/is_prime.hxx
new file mode 100644
index 0000000..da2b94d
--- /dev/null
+++ b/graphs/cpp/is_prime/is_prime.hxx
@@ -0,0 +1,21 @@
+#pragma once
+
+#include "is_prime.hh"
+constexpr bool is_prime(unsigned n)
+{
+ if (n == 0 || n == 1)
+ {
+ return false;
+ }
+ else
+ {
+ for (unsigned i = 2; i <= n / 2; ++i)
+ {
+ if (n % i == 0)
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+} \ No newline at end of file