# [CodeWars] Is a number prime?

Define a function `isPrime`/`is_prime()` that takes one integer argument and returns `true`/`True` or `false`/`False` depending on if the integer is a prime.

Per Wikipedia, a prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.

Example

 bool isPrime(5) = return true cs

Assumptions

• You can assume you will be given an integer input.
• You can not assume that the integer will be only positive. You may be given negative numbers as well (or `0`).

### My Solution

 bool isPrime(int num) {    if(num <= 1)        return false;    for (int i = 2; i <= sqrt(num); ++i)    {        if (num % i == 0)            return false;    }    return true;}Colored by Color Scripter cs
You can go as far as the square root of the number, not half the number, to determine which number is a decimal. Set the conditional statement separately since 0 and 1 are not unconditionally a few.

## 글쓴이: BakJH

Student of Daedeok SW Meister Highschool, in Korea.