Aditya Singh

Aditya Singh

  • NA
  • 1
  • 1.1k

Is this write code to chck prime num?if wrong plz tell m bst

Dec 16 2014 2:51 PM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrimeNumber
{
class Math
{
static void Main(string[] args)
{
Console.WriteLine("Enter a Number : ");
try
{
int num = int.Parse(Console.ReadLine());
if (num == 2 || num == 3 || num == 5 || num == 7)
{
Console.WriteLine("Entered number is Prime number");
}
else if (num % 2 != 0 && num % 3 != 0 && num % 5 != 0 && num % 7 != 0)
{
Console.WriteLine("Entered number is prime number");
}
else
{
Console.WriteLine("Entered number is not prime");
}
}
catch(Exception ee)
{
Console.WriteLine("Exception Raised Please Enter the valid number",ee);
}
Console.ReadLine();
}
}
}

Answers (1)