Dim a(1 To 50) As Integer
Private Sub Command1_Click()
Print "素数:"
Dim Counter As Integer
For i = 1 To 50
If IsPrimeNumber(a(i)) Then
Counter = Counter + 1
Print a(i);
If Counter Mod 10 = 0 Then Print
End If
Next i
Print
Print
End Sub
Private Sub Command2_Click()
Print "闰年:"
Dim Counter As Integer
For i = 1 To 50
If IsLeapyear(a(i)) Then
Counter = Counter + 1
Print a(i);
If Counter Mod 10 = 0 Then Print
End If
Next i
Print
End Sub
Private Sub Form_Load()
Randomize
Me.AutoRedraw = True
For i = 1 To 50
a(i) = Int(Rnd * 9000 + 1000)
Print a(i);
If i Mod 10 = 0 Then Print
Next i
Print
End Sub
Private Function IsPrimeNumber(ByVal n) As Boolean
IsPrimeNumber = True
For i = 2 To Sqr(n)
If n Mod i = 0 Then
IsPrimeNumber = False
Exit Function
End If
Next i
End Function
Private Function IsLeapyear(ByVal n As Integer) As Boolean
If (n Mod 400 = 0 And n Mod 3200 <> 0) Or (n Mod 4 = 0 And n Mod 100 <> 0) Then
IsLeapyear = True
Else
IsLeapyear = False
End If
End Function