From dc525bc9e4df06fcb338bfe0fe27acbde7b4d4fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9D=96=92=F0=9D=96=8E=F0=9D=96=8D=F0=9D=96=93?= =?UTF-8?q?=F0=9D=96=8A=F0=9D=96=86=20=F0=9D=96=92=F0=9D=96=94=F0=9D=96=98?= =?UTF-8?q?=F0=9D=96=94?= <105068494+MihneaMoso@users.noreply.github.com> Date: Wed, 1 Jan 2025 23:18:36 +0200 Subject: [PATCH 1/2] Create check-prime.md --- snippets/cpp/basics/check-prime.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 snippets/cpp/basics/check-prime.md diff --git a/snippets/cpp/basics/check-prime.md b/snippets/cpp/basics/check-prime.md new file mode 100644 index 00000000..cb4a2a8c --- /dev/null +++ b/snippets/cpp/basics/check-prime.md @@ -0,0 +1,26 @@ +--- +title: Check Prime Number +description: Check if an integer is a prime number +tags: cpp, number, prime +author: MihneaMoso +--- + +```cpp +bool is_prime(int n) { + if (n < 2) return false; + if (n == 2 || n == 3) return true; + if (n % 2 == 0) return false; + for (int i = 3; i * i <= n; i += 2) { + if (n % i == 0) return false; + } + return true; +} + +// Usage +#include + +int main() { + std::cout << is_prime(29) << std::endl; // Output: 1 + return 0; +} +``` From 1734cd033d1833823c309e38845063cfc16374a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9D=96=92=F0=9D=96=8E=F0=9D=96=8D=F0=9D=96=93?= =?UTF-8?q?=F0=9D=96=8A=F0=9D=96=86=20=F0=9D=96=92=F0=9D=96=94=F0=9D=96=98?= =?UTF-8?q?=F0=9D=96=94?= <105068494+MihneaMoso@users.noreply.github.com> Date: Wed, 1 Jan 2025 22:06:18 +0000 Subject: [PATCH 2/2] created new category for math and numbers for cpp and moved check-prime into it --- snippets/cpp/{basics => math-and-numbers}/check-prime.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename snippets/cpp/{basics => math-and-numbers}/check-prime.md (100%) diff --git a/snippets/cpp/basics/check-prime.md b/snippets/cpp/math-and-numbers/check-prime.md similarity index 100% rename from snippets/cpp/basics/check-prime.md rename to snippets/cpp/math-and-numbers/check-prime.md