Answers for "find prime number in c #"

C#
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
-1

how to check prime number in c#

using System;  
  public class PrimeNumberExample  
   {  
     public static void Main(string[] args)  
      {  
          int n, i, m=0, flag=0;    
          Console.Write("Enter the Number to check Prime: ");    
          n = int.Parse(Console.ReadLine());  
          m=n/2;    
          for(i = 2; i <= m; i++)    
          {    
           if(n % i == 0)    
            {    
             Console.Write("Number is not Prime.");    
             flag=1;    
             break;    
            }    
          }    
          if (flag==0)    
           Console.Write("Number is Prime.");       
     }  
   }
Posted by: Guest on May-03-2021

C# Answers by Framework

Browse Popular Code Answers by Language