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;
}
@jsg55 While I'm not a beginner to the language, I am still "learning". But, stronger codes that I do implement, like encryption key generators (in which I do use this function), I don't post. As I do not want it to be public code. I will post small/medium sized codes that will aide people in developing diverse and somewhat simliar codes. A lot of people just don't understand the use of prime numbers, or even more simplistic mathematical factions.
@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.
hey it might just be me but i dont think your supposed to just insult the persons code, you should tell them why you think its weak and give them constructive critisism (didnt spell that right), that kind of stuff is going to discourage a beggining scripter really badly. especially one trying to learn a language like this one lol.