Created
November 13, 2014 11:24
-
-
Save anuradhawick/dcba72587d07e0492def to your computer and use it in GitHub Desktop.
Prime number tester
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
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