vb中 输出0~100的所有素数。(每行输出5个)
2个回答
展开全部
给你一个判断素数的函数吧,你要是还搞不定我再帮你写个工程;
Public Function IsSushu(ByVal pa As Integer) As Boolean
Dim pb As Integer = pa - 1
Dim res As Boolean = True
For i = 2 To pb
If pa Mod i = 0 Then
res = False
Exit For
End If
Next i
Return res
End Function
展开全部
Private Sub prime(ByVal x As Integer, ByRef f As Boolean)
f = False
For i = 2 To Sqr(x)
If x Mod i = 0 Then
f = True
Exit For
End If
Next
End Sub
Private Sub Form_Click()
Dim i As Integer, f As Boolean, k As Integer
For i = 2 To100
prime i, f
If Not f Then
k = k + 1
Print i;
If k Mod 5 = 0 Then Print
end if
Next
End Sub
f = False
For i = 2 To Sqr(x)
If x Mod i = 0 Then
f = True
Exit For
End If
Next
End Sub
Private Sub Form_Click()
Dim i As Integer, f As Boolean, k As Integer
For i = 2 To100
prime i, f
If Not f Then
k = k + 1
Print i;
If k Mod 5 = 0 Then Print
end if
Next
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询