what is the formula for prime numbers

im writing a program to test numbers to see if they are prime but what is the most recomendable formula?
If the number is divisible by any of the number which came before it till 2, is NOT a prime. For ex. if 8 is divisible by 7,6,5,4,3,2 then it is NOT a prime.
You can find many algorithms regarding this on wikipedia: http://en.wikipedia.org/wiki/Primality_test
how can i do that in c++
for example to check if a number is even or odd:

if (number%2 ==0)
cout<< "That number is even" <<endl;
else
cout<< "that number is odd" <<endl;

how would i do it to see if any number is prime??
1. Take the number which to want to check
2. Start a loop from this number-1 till 2
3. Inside the loop check if the given number is divisible by any of the numbers in loop.
4. If yes, then flag = 1 and break from the loop (flag is a normal int or bool variable)
5. else, flag = 0, continue;
6. Outside the loop check if flag = 0 or 1, if 0 then number is prime else not prime

PS Make sure you are breaking from the loop if the number is divisible
LOL to original post. If such a simple formula existed then encryption would be a thing of the past.
Topic archived. No new replies allowed.