VB窗体上包含有两个名称分别为Op1和Op2的单选按钮,标题分别为“100-200的素数和” 和“200-400的素数和”
窗体上包含有两个名称分别为Op1和Op2的单选按钮,标题分别为“100-200的素数和”和“200-400的素数和”。还有一个文本框和一个命令按钮,标题分别为“求和”。程...
窗体上包含有两个名称分别为Op1和Op2的单选按钮,标题分别为“100-200的素数和” 和“200-400的素数和”。还有一个文本框和一个命令按钮,标题分别为“求和”。程序运行后,选中某个单选按钮,并单击“求和”按钮,则计算指明范围内的素数之和,并显示在文本框中。
展开
2个回答
展开全部
Private Sub Command1_Click()
Dim m%, sum%, i%, tag As Boolean
s = 0
If Option1.Value = True Then
For n = 100 To 200
tag = True
For i = 2 To n - 1
If n Mod i = 0 Then tag = False
Exit For
Next i
If tag = True Then sum = sum + n
Next n
Else
For n = 201 To 400
tag = True
For i = 2 To n - 1
If n Mod i = 0 Then tag = False
Exit For
Next i
If tag = True Then sum = sum + n
Next n
End If
Text1.Text = sum
End Sub
Dim m%, sum%, i%, tag As Boolean
s = 0
If Option1.Value = True Then
For n = 100 To 200
tag = True
For i = 2 To n - 1
If n Mod i = 0 Then tag = False
Exit For
Next i
If tag = True Then sum = sum + n
Next n
Else
For n = 201 To 400
tag = True
For i = 2 To n - 1
If n Mod i = 0 Then tag = False
Exit For
Next i
If tag = True Then sum = sum + n
Next n
End If
Text1.Text = sum
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
If a Mod b = 0 Then
Exit For
End If
Next b
If a = b Then
sum = sum + a
End If
Next a
Else
For a = 200 To 400
For b = 2 To a - 1
If a Mod b = 0 Then
Exit For
End If
Next b
If a = b Then
sum = sum + a
End If
Next a
End If
Text1.Text = sum
End Sub
Exit For
End If
Next b
If a = b Then
sum = sum + a
End If
Next a
Else
For a = 200 To 400
For b = 2 To a - 1
If a Mod b = 0 Then
Exit For
End If
Next b
If a = b Then
sum = sum + a
End If
Next a
End If
Text1.Text = sum
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询