DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Find if number is prime - C#
public bool IsPrime(int num)
{
bool _isPrime = true;
if (num % 2 == 0) return false;
for (int i = 3; i <= Convert.ToInt32(Math.Sqrt(num)); i = i + 2)
{
if (num % i == 0)
{
_isPrime = false;
break;
}
}
return _isPrime;
}
Find if number is prime - C#





