vb编程。编写一个程序prime(m%),判断m是否为素数,若是,函数返回值为true,否则为false。多谢啦
1个回答
展开全部
Private Sub Command1_Click()
Dim n%, i%
For n = 2 To 200
If prime(n) Then
Print n,
i = i + 1
If i Mod 4 = 0 Then Print
End If
Next n
End Sub
Private Function prime(m%) As Boolean
Dim i%, f As Boolean
f = True
For i = 2 To Sqr(m)
If m Mod i = 0 Then
f = False
Exit For
End If
Next i
prime = f
End Function
Dim n%, i%
For n = 2 To 200
If prime(n) Then
Print n,
i = i + 1
If i Mod 4 = 0 Then Print
End If
Next n
End Sub
Private Function prime(m%) As Boolean
Dim i%, f As Boolean
f = True
For i = 2 To Sqr(m)
If m Mod i = 0 Then
f = False
Exit For
End If
Next i
prime = f
End Function
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询