第1个回答 2014-12-12
我给你优化了一下,由于最大99,所以只需要判断到9就可以了,一旦j=10,则为素数
Private Sub Command1_Click()
Randomize
Dim i As Integer, j As Integer, n As Integer, nl As Integer, st As Integer
For i = 1 To 10
n = Int(Rnd * 90 + 10)
st = st & n & " "
For j = 2 To 9
If n Mod j = 0 Then Exit For
Next j
If j = 10 Then
nl = nl + 1
End If
Next i
Text1.Text = st
Text2.Text = nl
End Sub
第2个回答 2014-12-11
n = Int(Rnd * 90 + 10)本回答被提问者采纳
第3个回答 2014-12-11
已经改好了:
Private Sub Command1_Click()
Randomize
Dim i As Integer, j As Integer, n As Integer, nl As Integer, st As String
For i = 1 To 10
n = Int(Rnd * 99 + 10)
st = st & n & " "
For j = 2 To n - 1
If n Mod j = 0 Then Exit For
Next j
If j = n Then
nl = nl + 1
End If
Next i
Text1.Text = st
Text2.Text = nl
End Sub
第4个回答 2018-01-05
st As String