关于Vb的编程题,求100到999之间最大的三个素数 希望能给出具体的代码~~在线等 谢谢啦

2024年12月05日 14:16
有2个网友回答
网友(1):

Private Sub Command1_Click()
Dim k As Integer, i As Integer
Dim m
k = 0
For m = 999 To 100 Step -1
i = 2
Do While m Mod i <> 0 '判断是否是素数
i = i + 1
Loop
If i = m Then '是素数
Print m
k = k + 1
If k = 3 Then Exit For
End If
Next m
End Sub

网友(2):

------------------------分割线---------------------------------
Private Sub form_load()
Me.AutoRedraw = True
e = 1
For i = 999 To 100 Step -1
d = 0
For a = 2 To i
If i Mod a = 0 Then
Exit For
Else
d = d + 1
End If
Next
If d = i - 2 Then
Print i
e = e + 1
If e = 4 Then Exit Sub
End If
Next
End Sub
------------------------分割线---------------------------------