Created
October 11, 2012 06:38
-
-
Save juanfal/3870612 to your computer and use it in GitHub Desktop.
simplest way of computing primality. Know if a number is prime. Slowest way
This file contains 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
// 02.esprimo_simple.cpp | |
// juanfc 2009-10-16 | |
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
cout << "Please enter an integer: "; | |
int n; | |
cin >> n; | |
int i = 2; | |
while (i < n and n % i != 0) // is necessary i<n? | |
++i; | |
if (i >= n) | |
cout << "YES, it is prime" << endl; | |
else | |
cout << "NO, it is not a prime" << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment