Created
June 22, 2010 14:21
-
-
Save betawaffle/448519 to your computer and use it in GitHub Desktop.
Is n a prime number?
This file contains hidden or 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
int is_prime(unsigned n) { | |
unsigned c; | |
if (n < 2) return 0; | |
for (c = 2; c < n; c++) { | |
if ((n % c) == 0) return 0; | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't take credit for this. It's just a handy thing to have if you want a quick, simple (and inefficient) way to check whether a number is prime.