关于Vb的编程题,求100到999之间最大的三个素数 希望能给出具体的代码~~在线等 谢谢啦
2个回答
展开全部
Private Sub Command1_Click()
Dim k As Integer, i As Integer
Dim m
k = 0
For m = 999 To 100 Step -1
i = 2
Do While m Mod i <> 0 '判断是否是素数
i = i + 1
Loop
If i = m Then '是素数
Print m
k = k + 1
If k = 3 Then Exit For
End If
Next m
End Sub
Dim k As Integer, i As Integer
Dim m
k = 0
For m = 999 To 100 Step -1
i = 2
Do While m Mod i <> 0 '判断是否是素数
i = i + 1
Loop
If i = m Then '是素数
Print m
k = k + 1
If k = 3 Then Exit For
End If
Next m
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
------------------------分割线---------------------------------
Private Sub form_load()
Me.AutoRedraw = True
e = 1
For i = 999 To 100 Step -1
d = 0
For a = 2 To i
If i Mod a = 0 Then
Exit For
Else
d = d + 1
End If
Next
If d = i - 2 Then
Print i
e = e + 1
If e = 4 Then Exit Sub
End If
Next
End Sub
------------------------分割线---------------------------------
Private Sub form_load()
Me.AutoRedraw = True
e = 1
For i = 999 To 100 Step -1
d = 0
For a = 2 To i
If i Mod a = 0 Then
Exit For
Else
d = d + 1
End If
Next
If d = i - 2 Then
Print i
e = e + 1
If e = 4 Then Exit Sub
End If
Next
End Sub
------------------------分割线---------------------------------
追问
谢谢高手啦,不过还有一个小问题诶
If d = i - 2 Then---------这里为什么用d= i-2,不懂是什么意思
Print i
e = e + 1
If e = 4 Then Exit Sub
End If
Next
End Sub
追答
d= i-2
因为循环语句 for a = 2 To i ,我是从2开始遍历数字的,所以要去掉2个没有被计算在内的数字
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询