Created
March 12, 2020 14:29
-
-
Save lablnet/ef93c82abd7f1f6d8c80be0f0cd960d7 to your computer and use it in GitHub Desktop.
C++ prime find prime number using exhaustive enumeration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| namespace lablnet { | |
| bool is_prime(int n) | |
| { | |
| bool isPrime = true; | |
| for (int i = n - 1; i >= 2; i--) | |
| { | |
| if (n % i == 0) | |
| { | |
| isPrime = false; | |
| break; | |
| } | |
| } | |
| return isPrime; | |
| } | |
| } | |
| int main() | |
| { | |
| bool isPrime = true; | |
| int n; | |
| cout << "Enter a positive integer \t"; | |
| cin >> n; | |
| if (lablnet::is_prime(n)) | |
| cout << "This is a prime number"; | |
| else | |
| cout << "This is not a prime number"; | |
| return 1; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment