Advertisement
Donald_Fortier

bool isPrime( int );// C++

May 28th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. using namespace std;
  2.  
  3. bool isPrime( int );// Prototype for this function.
  4.  
  5. bool isPrime( int num ) {
  6.     for ( int divisor = 2; divisor <= num / 2; divisor++ )// For all divisors from 2 to 1/2 of the number...
  7.         if ( num % divisor == 0 )// If it divides evenly with no remainder...
  8.             return false;// then it is not a prime since it's dividable by something.
  9.  
  10.     return true;// It wasn't dividable by anything from 2 to 1/2 of the number, so it must be prime.
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement