protected void Button1_Click(object sender, EventArgs e)
{
//SPECIFYING NUMBER RANGE
for (int i = 1; i <= 40; i++)
{
bool a = CheckNo(Convert.ToInt32(i));
if (a == true)
{
Response.Write(i + " " + "Number is Prime" + " ");
}
else
{
Response.Write(i + " " + "Number is Not Prime" + " );
}
}
}
//FUNCTION FOR DETECTING PRIME NUMBERS
protected bool CheckNo(int number)
{
bool Flag = true;
if (number == 1 && number == 2)
{
Flag = false;
}
for (int i = number - 1; i >= 2; i--)
{
if (number % i == 0)
{
Flag = false; break;
}
}
return Flag;
}