VB这题哪里出错了?
问题在图片里PrivateSubCommand1_Click()Fori=100To1000Forj=2Toi-1IfiModj=0ThenExitForElses=s+...
问题在图片里
Private Sub Command1_Click()
For i = 100 To 1000
For j = 2 To i - 1
If i Mod j = 0 Then
Exit For
Else
s = s + i
Exit For
End If
Next j
Next i
Print s
End Sub 展开
Private Sub Command1_Click()
For i = 100 To 1000
For j = 2 To i - 1
If i Mod j = 0 Then
Exit For
Else
s = s + i
Exit For
End If
Next j
Next i
Print s
End Sub 展开
展开全部
Private Sub Command1_Click()
s=0
For i = 100 To 1000
ok=1
For j = 2 To i - 1
If i Mod j = 0 Then
ok=0
Exit For
End If
Next j
if ok=1 then s=s+i
Next i
Print s
End Sub
s=0
For i = 100 To 1000
ok=1
For j = 2 To i - 1
If i Mod j = 0 Then
ok=0
Exit For
End If
Next j
if ok=1 then s=s+i
Next i
Print s
End Sub
追问
我老师给的也是和你一样的,我想知道一下我那样写是哪里出错了吗
追答
你的代码根本无法判断i是否质数,j的循环在第一次执行j=2之后立即跳出了,只判定了i是否可以整除2
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询