A simple function to check if a number is a prime or not. It will return true or false.

Edit: Please don't leave a blunt comment saying prime numbers aren't useful... Prime numbers are ONLY useful in computing and CS... They are a key feature in security. And unless you can list every prime number off the top of your head, this is a useful resource.

```
bool pnumf(const int num)
{
int f=0;
bool p;
for (int a=num;a>1;a--)
{
f = (num%a == 0) ? f+1 : f;
}
p = (f>1 || num==1) ? false : true;
return p;
}
```

Sign in to comment.

@bielle It's useful if you're using it inline. It's not meant to return the prime number.

@ssimar If you're going to reply with a blatant, and disrespectful comment, don't bother leaving one.

A very useful resource in finding prime numbers is stronger encryption. As there are only so many factors when multiiplying them. When multiplying two prime numbers together instead of any two ordinary numbers, there are only four factors, making the encryption key stronger, which makes it harder to crack.

Are you sure you want to unfollow this person?

Are you sure you want to delete this?

Click "Unsubscribe" to stop receiving notices pertaining to this post.

Click "Subscribe" to resume notices pertaining to this post.