A prime number (or a prime) is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways of writing it as a product, 1 × 5 or 5 × 1, involve 5 itself. However, 6 is composite because it is the product of two numbers (2 × 3) that are both smaller than 6. Primes are central in number theory because of the fundamental theorem of arithmetic: every natural number greater than 1 is either a prime itself or can be factorized as a product of primes that is unique up to their order.

source: Wikipedia

Considering a number n we can find out whether it is prime or not applying by the following C++ algorithm:

#include <iostream.h>
long int n, prim, d;
while (d<=n/2)
{if (n%d==0) 
if (prim==1)
else cout<<"No";