C# Program to Check Number is Prime or not


-

-

Example:

Copied
using System;  
public class CheckPrimeOrNot  
{  
    public static void Main(string[] args)  
    {  
        int n, i, m=0, flag=0;    
        Console.Write("Enter any Number: ");    
        n = int.Parse(Console.ReadLine());  
        m=n/2;   
        
        for(i = 2; i <= m; i++)    
        {    
            if(n % i == 0)    
            {    
                Console.Write("\nIt is Prime Number");    
                flag=1;    
                break;    
            } 
        }    
        if (flag==0)    
           Console.Write("\nIt is not Prime Number");       
     }  
   }  

Output:

Enter any Number:
15
It is Prime Number