Skip to content

Instantly share code, notes, and snippets.

@anuradhawick
Created November 13, 2014 11:24
Show Gist options
  • Save anuradhawick/dcba72587d07e0492def to your computer and use it in GitHub Desktop.
Save anuradhawick/dcba72587d07e0492def to your computer and use it in GitHub Desktop.
Prime number tester
typedef int bool;
#define true 1
#define false 0
bool prime(long long int n){
long long int i;
if(n<=0 || n==1 || (n%2==0 && n!=2)){
return false;
}
else if(n==2 || n==3){
return true;
}
for(i=3;i<(int)sqrt(n)+1;i=i+2){
if(n%i==0) return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment