主题:[原创]新手的失败之作!请大家指点...
[em6][em6]
我要求比N小的所有素数!如下:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i, j, n As Integer
j=2
n = Val(TextBox1.Text)
TextBox2.Text = Str(1) + Str(2) + " " '1,2是素数
For j = 2 To n - 1
j = j + 1
For i = 2 To j - 1
If j mod i = 0 Then Exit For '能整除表示该数不是素数,所以标记不是素数
End
Next i
If j = i Then
TextBox2.Text = textbox2.text + " "
End If
Next j
End Sub
请大家提出你的思路,最好能写几行!
我要求比N小的所有素数!如下:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i, j, n As Integer
j=2
n = Val(TextBox1.Text)
TextBox2.Text = Str(1) + Str(2) + " " '1,2是素数
For j = 2 To n - 1
j = j + 1
For i = 2 To j - 1
If j mod i = 0 Then Exit For '能整除表示该数不是素数,所以标记不是素数
End
Next i
If j = i Then
TextBox2.Text = textbox2.text + " "
End If
Next j
End Sub
请大家提出你的思路,最好能写几行!