Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

prime number program in c

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;
}
 
PREVIOUS NEXT
Tagged: #prime #number #program
ADD COMMENT
Topic
Name
6+6 =