VB小题目,高手帮忙啊!!

来源:百度知道 编辑:UC知道 时间:2024/07/07 14:11:46
求一个指定整数以内的所有素数(注意不是判断是否是素数而是输入两个数,把这个两个数之间的所有素数输出)
要求:用inputbox函数输入,用FOR循环做!

dim bool as boolean
bool as false
m=inputbox("小的")
n=inputbox("大的")
for i=m to n
for j=2 to i-1
if i mod j=0 then
bool = true
next j
if bool =true then
print j ;" ";
bool=false
next i

Function s(n1 As Long, n2 As Long) As Boolean
Dim max As Long, min As Long
Dim n As Long
If n1 > n2 Then
max = n1: min = n2
Else
max = n2: min = n1
End If
For n = min To max
If ss(n) = True Then
Debug.Print n
End If
Next
End Function

Function ss(Tmp As Long) As Boolean '素数判断
ss = True
For i = 2 To Tmp / 2
If Tmp Mod i = 0 Then
ss = False
Exit Function
End If
Next
End Function

Private Sub Form_Click()
Dim a As Long
Dim b As Long
a = Val(InputBox("请输入第一个整数", "输入框"))
b = Val(InputBox("请输入第二个整数", "