Skip to content

Instantly share code, notes, and snippets.

@geneorama
Created February 10, 2012 17:17
Show Gist options
  • Save geneorama/1791047 to your computer and use it in GitHub Desktop.
Save geneorama/1791047 to your computer and use it in GitHub Desktop.
jims_prime_number_cheker
#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