Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- bool isPrime( int );// Prototype for this function.
- bool isPrime( int num ) {
- for ( int divisor = 2; divisor <= num / 2; divisor++ )// For all divisors from 2 to 1/2 of the number...
- if ( num % divisor == 0 )// If it divides evenly with no remainder...
- return false;// then it is not a prime since it's dividable by something.
- return true;// It wasn't dividable by anything from 2 to 1/2 of the number, so it must be prime.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement