Created
February 10, 2012 17:17
-
-
Save geneorama/1791047 to your computer and use it in GitHub Desktop.
jims_prime_number_cheker
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
#include<iostream> | |
#include<cmath> | |
#include<stdlib.h> | |
using namespace std; | |
int main() { | |
int n,i; | |
int is_prime = true; | |
cout << "Enter a number and press ENTER: "; | |
cin >> n; | |
i=2; | |
while (i<=sqrt(n)) { | |
if(n%i==0){ | |
is_prime=false; | |
break; | |
} | |
i++; | |
} | |
if (is_prime) { | |
cout << "Number is prime." <<endl; | |
} else { | |
cout << "Number is not prime." << endl; | |
cout << "It is divisible by " << i << endl; | |
} | |
system("PAUSE"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment