Answers for "isprime c#"

C#
4

isprime c#

public static bool IsPrime(int number)
{
    if (number <= 1) return false;
    if (number == 2) return true;
    if (number % 2 == 0) return false;

    var boundary = (int)Math.Floor(Math.Sqrt(number));

    for (int i = 3; i <= boundary; i+=2)
        if (number % i == 0)
            return false;

    return true;        
}
Posted by: Guest on June-18-2020

C# Answers by Framework

Browse Popular Code Answers by Language