这是我的代码片段。基本上,一旦单击按钮,此逻辑就会触发并确定数字是否为素数。问题是一些数字返回为“非质数”,而实际上它们是。谁能指出缺陷在哪里?
谢谢
private void bntTestPrime_Click(object sender, EventArgs e)
{
int num;
double num_sqrt;
int num_fl;
num = Convert.ToInt32(txtInput.Text);
num_sqrt = Math.Sqrt(num);
num_fl = Convert.ToInt32(Math.Floor(num_sqrt));
for (int i = 1; i <= num_fl; i++)
{
if (num % i == 0 && i != num)
lblResult_prime.Text = "Number " + num + " is not Prime.";
else
lblResult_prime.Text = "Number " + num + " is Prime.";
}
}