vb代码问题 找出100以内所有素数,存放于数组prime中。并将所找到的数,按每行10个的形式显示在窗体上
1个回答
推荐于2017-05-31
展开全部
Option Explicit
Private Sub Form_Click()
Dim i As Long, j As Long, n As Integer, prime() As Integer
For i = 1 To 100
If fc(i) Then
n = n + 1
ReDim Preserve prime(1 To n)
prime(n) = i
End If
Next
For i = 1 To n
Print prime(i);
If i Mod 10 = 0 Then Print
Next
Print: Print "共有:" & n
End Sub
Function fc(a) As Boolean
Dim i As Long
For i = 2 To Int(a / 2)
If a Mod i = 0 Then Exit For
Next
If i = Int(a / 2) + 1 Then fc = True
End Function
Private Sub Form_Click()
Dim i As Long, j As Long, n As Integer, prime() As Integer
For i = 1 To 100
If fc(i) Then
n = n + 1
ReDim Preserve prime(1 To n)
prime(n) = i
End If
Next
For i = 1 To n
Print prime(i);
If i Mod 10 = 0 Then Print
Next
Print: Print "共有:" & n
End Sub
Function fc(a) As Boolean
Dim i As Long
For i = 2 To Int(a / 2)
If a Mod i = 0 Then Exit For
Next
If i = Int(a / 2) + 1 Then fc = True
End Function
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询