In this program, you will write prime number program in c# and check whether a number is prime or not in the c# program
The number which will divide by 1 or itself is called a prime number. For example 2, 3, 5, 7, 11, 13, .... are the prime numbers.
using System;
class Prime {
public static void Main() {
int num,i,flag=0;
Console.Write("Enter the number:");
num=int.Parse(Console.ReadLine());
for(i=2;i<=(num/2);i++)
{
if(num%i==0)
flag=1;
}
if(flag==0)
Console.Write(num+" is a prime number");
else
Console.Write(num+" is a not prime number");
}
}
Enter the number:23 23 is a prime number