Skip to content

Instantly share code, notes, and snippets.

@jeremy5189
Created March 6, 2014 07:09
Show Gist options
  • Save jeremy5189/9383969 to your computer and use it in GitHub Desktop.
Save jeremy5189/9383969 to your computer and use it in GitHub Desktop.
int isPrime( int n ) {
if( n <= 2 )
return true;
else if( n % 2 == 0 )
return false;
else {
int i, sn = (int)sqrt((double)n) + 1;
for( i = 3; i <= sn; i++ ) {
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