Answers for "program to print prime number series in C#"

C#
2

get prime number c#

// Assuming that the number passed is higher than 1.


// This function will check if the number is prime by using all the previous
// numbers. There's no need to check further than the square root 
// Returns true or false.
public static bool isPrime(int number)
        {
            double sqrNum = Math.Sqrt(number);
            for (int i = 2; i <= sqrNum; i++) if (number % 2 == 0) return false;
            return true;
        }


// This function is essentially the same
// but will only compare with numbers from a prime number list
public static bool isPrime(int number, int[] primeList) 
       {
            double sqrNum = Math.Sqrt(number);

            foreach(int prime in primeList) { 
                if (prime > sqrNum) return true;
                else if (number % prime==0) return false;
            }
            return true;
       }
// You can expand your primeList using any of the functions, 
//to better use the second function.
Posted by: Guest on August-06-2021
0

find prime number in c #

static Boolean PrimerNumber (int x) //The function return a value of true or false for a prime number
        {
            int i, count=0;
            bool flag=false;
            for (i = 2; i < x; i++)
            {
                if (x % i == 0)
                {
                    cont = 1;
                    break;
                }
            }
            if (count == 0)
                flag = true;
            return flag;
        }
Posted by: Guest on May-22-2021

Code answers related to "program to print prime number series in C#"

C# Answers by Framework

Browse Popular Code Answers by Language