using System;
class Program
{
public static void Main()
{
Console.WriteLine("Enter a number to check its prime number or not");
int Num = int.Parse(Console.ReadLine());
int count = 0;
if (Num == 0 || Num == 1)
{
Console.WriteLine("{0} is not a prime",Num);
}
else if (Num == 2)
{
Console.WriteLine("2 is even prime Number");
}
else
{
for (int i = 2; i <= Num/2; i++)
{
if (Num % i == 0)
{
count++;
break;
}
}
if (count> 0)
{
Console.WriteLine("{0} is not a prime number", Num);
}
else
{
Console.WriteLine("{0} is a prime number",Num);
}
}
}
}
class Program
{
public static void Main()
{
Console.WriteLine("Enter a number to check its prime number or not");
int Num = int.Parse(Console.ReadLine());
int count = 0;
if (Num == 0 || Num == 1)
{
Console.WriteLine("{0} is not a prime",Num);
}
else if (Num == 2)
{
Console.WriteLine("2 is even prime Number");
}
else
{
for (int i = 2; i <= Num/2; i++)
{
if (Num % i == 0)
{
count++;
break;
}
}
if (count> 0)
{
Console.WriteLine("{0} is not a prime number", Num);
}
else
{
Console.WriteLine("{0} is a prime number",Num);
}
}
}
}
No comments:
Post a Comment