Search
 
SCRIPT & CODE EXAMPLE
 

CPP

prime number program

bool isPrime(int x = 0)
{
    /* Without extra 'count' variable */
    //! corner case: 0 and 1 aren't prime numbers
    if (x == 0 || x == 1)
        return 0;

    for (int i = 2; i <= x / 2; i++)
    {
        if (x > 2 && x % i == 0)
            return 0;
    }

    return 1;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: quick sort c++ 
Cpp :: char vector to string c++ 
Cpp :: finding size of columns and rows in 2d vector c++ 
Cpp :: cout.flush() in c++ 
Cpp :: arduino led code 
Cpp :: convert vector into array c++ 
Cpp :: Modulo Exponentiaon,Iteratve Modulo Exponentiation 
Cpp :: convert string to number c++ 
Cpp :: rank() in c++ 
Cpp :: how to write a hello world program in c++ 
Cpp :: binary string addition 
Cpp :: initialize 2d array c++ memset 
Cpp :: 2d vector c++ declaration 
Cpp :: array 2d dynamic allocation c++ 
Cpp :: c++ product of vector 
Cpp :: how to add numbers in c++ 
Cpp :: how to do (binary) operator overloading in c++ 
Cpp :: how to run a msi file raspbrain 
Cpp :: iff arduino 
Cpp :: c++ string comparison 
Cpp :: c++ constructors 
Cpp :: arguments to a class instance c++ 
Cpp :: C++ Swap 2 Variables Without Using 3rd Variable 
Cpp :: string to long integer c++ 
Cpp :: c++ cout colored output xcode 
Cpp :: minimum value in array using c++ 
Cpp :: c++ cast char to string 
Cpp :: file c++ 
Cpp :: C++ String Length Example 
Cpp :: time of a loop in c++ 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =