vb程序输入任意一个整数,求1到n的所有质数
2个回答
2012-11-21
展开全部
Private Sub Command1_Click()
Dim k As Integer, i As Integer, m As Integer
k = Val(InputBox("请输入一个整数"))
For i = 1 To k
If ss(i) Then
Print i;
m = m + 1
If m Mod 8 = 0 Then Print
End If
Next i
End Sub
Function ss(n As Integer) As Boolean
ss = True
If n <= 1 Then
ss = False
Exit Function
End If
For i = 2 To n - 1
If n Mod i = 0 Then
ss = False
Exit Function
End If
Next i
End Function
Dim k As Integer, i As Integer, m As Integer
k = Val(InputBox("请输入一个整数"))
For i = 1 To k
If ss(i) Then
Print i;
m = m + 1
If m Mod 8 = 0 Then Print
End If
Next i
End Sub
Function ss(n As Integer) As Boolean
ss = True
If n <= 1 Then
ss = False
Exit Function
End If
For i = 2 To n - 1
If n Mod i = 0 Then
ss = False
Exit Function
End If
Next i
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询