code to check whether a number is prime or not.

Ddd
Posted by Ddd under C# category on | Points: 40 | Views : 17815
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication20jan
{
class Class5
{
static void Main()
{
Console.WriteLine("Enter number : ");
int n = Convert.ToInt32(Console.ReadLine());
for (int a = 2; a <= n / 2; a++)
{
if (n % a== 0)
{
Console.WriteLine("Number is not prime");
return;
}
}
Console.WriteLine("Number is Prime");

}
}
}

Comments or Responses

Login to post response