'题1---------------------------------
Private Sub Command1_Click()
' 素数大于1,唯一的偶数是2
Dim i As Integer, j As Integer, blnsushu As Boolean
Dim sushu() As Integer, sushuNUM As Integer, jishu() As Integer, oushu() As Integer
Dim sushuNUM1 As Integer, sushuNUM2 As Integer
ReDim sushu(0 To 0)
ReDim jishu(0 To 0)
ReDim oushu(0 To 0)
sushuNUM = 0
For i = 2 To 100
blnsushu = True
For j = 2 To i - 1
If i Mod j = 0 Then
blnsushu = False
Exit For
End If
Next j
If blnsushu Then
ReDim Preserve sushu(0 To sushuNUM)
sushu(sushuNUM) = i
sushuNUM = sushuNUM + 1
End If
Next i
sushuNUM1 = 0
For i = 0 To UBound(sushu)
If sushu(i) Mod 2 = 0 Then
ReDim Preserve oushu(0 To sushuNUM1)
oushu(sushuNUM1) = sushu(i)
sushuNUM1 = sushuNUM1 + 1
Else
ReDim Preserve jishu(0 To sushuNUM2)
jishu(sushuNUM2) = sushu(i)
sushuNUM2 = sushuNUM2 + 1
End If
Next i
For i = 0 To UBound(jishu)
Print jishu(i)
Next i
For i = 0 To UBound(oushu)
Print oushu(i)
Next i
End Sub
'题2---------------------------------
Dim a(5) As Integer
Private Sub Command2_Click()
Dim shuru As Integer, weizhi As Integer
shuru = Val(Text1.Text)
If find(shuru, weizhi) Then
MsgBox "数字" & shuru & "在数组的第" & weizhi & "个位置"
Else
MsgBox "输入数字不在数组内"
End If
End Sub
Private Function find(shuru As Integer, weizhi As Integer) As Boolean
Dim i As Integer
find = False
For i = LBound(a) To UBound(a)
If shuru = a(i) Then
find = True
weizhi = i + 1
End If
Next i
End Function
Private Sub Form_Load()
Dim i As Integer
For i = 0 To 4
Randomize
a(i) = Int(Rnd * 10) + 1
Next i
End Sub
Private Sub Form_click()
Dim x As String, i As Integer, j As Integer
For i = 1 To 9
x = ""
For j = 1 To i
x = x + "*" + " " '*号需要对称,此处需要加空格
Next j
x = Space(10 - i) & x
Print x
Next i
End Sub
Private Sub Form_click()
Dim i%
For i = 1 To 9
Print Tab(10 - i); String$(i, "*!" & " ")
Next i
End Sub