Skip to content

Instantly share code, notes, and snippets.

@betawaffle
Created June 22, 2010 14:21
Show Gist options
  • Save betawaffle/448519 to your computer and use it in GitHub Desktop.
Save betawaffle/448519 to your computer and use it in GitHub Desktop.
Is n a prime number?
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;
}
@betawaffle
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment