Monday, October 20, 2008

Check Prime numbers

Function to Check Prime number

Here a simple function to check whether the given number is Prime or not.


private bool isPrime(int tmp)
 {
   if (tmp <= 3)
    return true;
   else
   {
    for (int cnt = 2; cnt < tmp; cnt++)
    {
     if (tmp % cnt == 0)
      return false;
     }
    return true;
   }
 }

No comments: