Thursday 30 August 2012

Prime number in c sharp

How to write prime number in c sharp

namespace prime
{
class Program
{
static void Main(string[] args)
{
int no, i, flag;
flag = 1;
Console.WriteLine("Enter no. to be checked:");
no =Convert.ToInt16 ( Console.ReadLine());

for (i = 2; i <= no / 2; i++)
{
if (no % i == 0)
flag = 0;
}
if (flag == 1)
Console.WriteLine("Prime.");
else
Console.WriteLine("not Prime");
Console.ReadLine();
}

}
}
Share This
Previous Post
Next Post

FYJC XI standard online admisson Process and declaraton of Merit list . Cut off List For prevous year also . 10 Th Results onlne declaraton Maharashtra Region .

0 comments: