'笨法子 Private Sub Form_Load() Dim i As Integer Dim j As Integer Me.Show j = 0 For i = 3 To 100 If IsPrime(i) = True Then j = j + 1 Me.Print i,
End If If j Mod 4 = 0 Then Me.Print End If
Next
End Sub Private Function IsPrime(intNum As Integer) As Boolean Dim i As Integer
For i = 2 To intNum \ 2 If (intNum Mod i) = 0 Then IsPrime = False Exit Function End If Next IsPrime = TrueEnd Function
Private Sub Form_Load() Dim i As Integer Dim j As Integer Me.Show j = 0 For i = 3 To 100 If IsPrime(i) = True Then j = j + 1 Me.Print i, ------------------ ‘这段放在这里 If j Mod 4 = 0 Then Me.Print End If ------------------
End If
Next
End Sub
你留个Email,我前几天刚好帮一个师妹编了一个,我给你发过去
======================= 我的思路大致如下: ======================= '使用一数组存放素数,count变量记录当前个数: dim prime(100) as long dim count as long'先添加几个素数: prime(1)=3 prime(2)=5 count=2'然后从7开始: for i=7 to N step 2 '只需要计算奇数 '对i判断: if checkPrime(i) then count=count+1 '加1 prime(count)=i '把i放入数组 end if next i '输出...'这个函数检查n是不是素数: function checkPrime(byval n as long)as boolean for i=1 to count '遍历prime数组 '用prime数组的每个素数判断n: if n mod prime(i)=0 then exit function next i 如果prime中的每个素数都不能整除n,则n为素数: checkprime=true end function
Private Sub Form_Load()
Dim i As Integer
Dim j As Integer
Me.Show
j = 0
For i = 3 To 100
If IsPrime(i) = True Then
j = j + 1
Me.Print i,
End If
If j Mod 4 = 0 Then
Me.Print
End If
Next
End Sub
Private Function IsPrime(intNum As Integer) As Boolean
Dim i As Integer
For i = 2 To intNum \ 2
If (intNum Mod i) = 0 Then
IsPrime = False
Exit Function
End If
Next
IsPrime = TrueEnd Function
Dim i As Integer
Dim j As Integer
Me.Show
j = 0
For i = 3 To 100
If IsPrime(i) = True Then
j = j + 1
Me.Print i,
------------------
‘这段放在这里
If j Mod 4 = 0 Then
Me.Print
End If
------------------
End If
Next
End Sub
我的思路大致如下:
=======================
'使用一数组存放素数,count变量记录当前个数:
dim prime(100) as long
dim count as long'先添加几个素数:
prime(1)=3
prime(2)=5
count=2'然后从7开始:
for i=7 to N step 2 '只需要计算奇数
'对i判断:
if checkPrime(i) then
count=count+1 '加1
prime(count)=i '把i放入数组
end if
next i
'输出...'这个函数检查n是不是素数:
function checkPrime(byval n as long)as boolean
for i=1 to count '遍历prime数组
'用prime数组的每个素数判断n:
if n mod prime(i)=0 then exit function
next i
如果prime中的每个素数都不能整除n,则n为素数:
checkprime=true
end function
me.print TAB(7*(n mod 4));n