- Sat 09 January 2021
- prime
- #prime, #primenumbers

A prime is a positive integerphaving exactly two positive divisors, namely1andp. An integernis composite ifn>1andnis not prime. (The number 1 is considered neither prime nor composite.)

We can frame a brute force algorithm for checking primality of numbers using the above statement.

```
bool is_prime(int number) {
int factor = 0;
for (int i = 0; i <= number; ++i) {
if (number % i == 0) {
factor++;
}
}
return (factor == 2)? true : false;
}
```

This Blog is licensed under Attribution-NonCommercial 4.0 International