Created
January 31, 2024 08:58
-
-
Save philopaterwaheed/fe0156377d7085de1a80937e723bb2b7 to your computer and use it in GitHub Desktop.
a function to determine if a number is prime or now
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
bool is_prime (int n ) | |
{ | |
if (n == 2 ) | |
return true; | |
if ( n == 1 ) | |
return false ; | |
for (int i =2 ; i * i < (n) ; 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