find prime numbers in c#.net code example
Example 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.");
}
}
Example 2: find prime number in c #
static Boolean PrimerNumber (int x)
{
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;
}