找出一千以内所有素数 的VB程序
2个回答
2013-05-31
展开全部
Private Sub Command1_Click()
Dim i As Integer, j As Integer
Dim bool As Boolean
For i = 2 To 1000
bool = False
For j = 2 To i - 1
If i Mod j = 0 Then
bool = True
Exit For
End If
Next j
If bool = False Then
Print i;
End If
Next i
End Sub
Dim i As Integer, j As Integer
Dim bool As Boolean
For i = 2 To 1000
bool = False
For j = 2 To i - 1
If i Mod j = 0 Then
bool = True
Exit For
End If
Next j
If bool = False Then
Print i;
End If
Next i
End Sub
2013-05-31
展开全部
Private Sub Form_Click()
For i = 2 To 1000
If sushu(i) = True Then
b = b + 1
If b Mod 10 = 0 Then Print
Print i;
End If
Next i
End Sub
Function sushu(x) As Boolean
For m = 2 To Sqr(x)
If x Mod m = 0 Then
sushu = False
Exit Function
End If
Next m
sushu = True
End Function
For i = 2 To 1000
If sushu(i) = True Then
b = b + 1
If b Mod 10 = 0 Then Print
Print i;
End If
Next i
End Sub
Function sushu(x) As Boolean
For m = 2 To Sqr(x)
If x Mod m = 0 Then
sushu = False
Exit Function
End If
Next m
sushu = True
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询