判断一个整数是否为素数的通用过程:
Dim i as integer
prime = True
For i =2 to sqr(n)
if n Mod i =0 Then prime = False Exit For End ifNext i100以内的素数:For I = 100 to 2 step -1 if prime (I) Then ReDim preserve S(k) S(k)=I k=k+1 Ene ifNext I5个一行输出:Private Sub Command1_() Dim i As Integer , j As Integer Randomize For i = 1 to UBound(a) For j = 1 to 5 a(i,j)=I Form1.print a(i,j) Next j From1.print Next iEnd Sub
Private Sub Command1_Click()
Dim i As Long, count As Long
For i = 3 To 100
If isprime(i) Then
Print i;
count = count + 1
If count Mod 4 = 0 Then Print
End If
Next i
End Sub
Public Function isprime(n As Long) As Boolean
Dim mark As Boolean
Dim i As Long
If n < 2 Then
isprime = False
Exit Function
End If
For i = 2 To n - 1
If n Mod i = 0 Then
mark = True
Exit For
End If
Next i
isprime = Not mark
End Function
Private Sub Form_Click()
Dim n As Integer
For i = 3 To 100
For j = 3 To Sqr(i)
If i Mod j = 0 Then Exit For
Next j
If j > Sqr(i) Then
Print i;
n = n + 1
If n = 4 Then
Print
n = 0
End If
End If
Next i
End Sub