C# Program to Check Whether a Number is Prime or Not
In this C# program, we will take input from the user and check whether the number is prime or not. A prime number is a positive integer that is divisible only by 1 and itself.
private static void Main(string[] args)
{
Console.ForegroundColor= ConsoleColor.Yellow;
int num;
bool Is_Prime_Number = true;
Console.WriteLine("Enter the Number to check Prime: ");
num = int.Parse(Console.ReadLine());
for (int i = 2; i <= num / 2; i++)
{
if (num % i == 0)
{
Console.WriteLine("Number is not Prime.");
Is_Prime_Number = false;
break;
}
}
if (Is_Prime_Number == true)
Console.WriteLine("Number is Prime.");
Console.ReadKey();
}
C# Program to Check Whether a Number is Prime or Not Output:

