Pages

Men

rh

6/10/2012

Write a Program Given Number is Prime Number or Not?


 protected void CheckGivenNumerIsPrimeOrNot()
 {
  int number = Convert.ToInt32(textBox1.Text);
  int i;
  for (i = 2; i < number; i++)
  {
   if (number % i == 0)
   {
     MessageBox.Show("Number is  not a prime");
     break;
   }
  }
  if(i==number)
  {
     MessageBox.Show("Number is  a prime");
  }
}

No comments :

Post a Comment