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();
}
}
}
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();
}
}
}
0 comments: