Program :
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Primenumber
{
class Program
{
static void Main(string[] args)
{
int num, flag = 0;
Console.WriteLine("Enter A number :");
num = Convert.ToInt32(Console.ReadLine());
if (num > 0)
{
for (int i = 2; i < num - 1; i++)
{
if (num % i == 0)
{
flag = 1;
break;
}
}
if (flag == 0)
Console.WriteLine("The number " + num + " is a Prime number .");
else
Console.WriteLine("The number " + num + " is not a Prime number .");
}
else
Console.WriteLine("Enter A valid Number :\n");
Console.ReadKey();
}
}
}
Output :
Enter A number :
5
The number 5 is a Prime number .
Enter A number :
6
The number 6 is not a Prime number .
Comments
Post a Comment