Vb编程:求100-999之间的所有素数
求100-999之间的所有素数,并在窗体上输出要求:自定义一个过程判断一个数是否是素数(答案正确追加30以上)...
求100-999之间的所有素数,并在窗体上输出
要求:自定义一个过程判断一个数是否是素数
(答案正确追加30以上) 展开
要求:自定义一个过程判断一个数是否是素数
(答案正确追加30以上) 展开
2个回答
展开全部
我只会判断是不是素数,因为我是个VB菜鸟.
希望你能用得上.
Private Sub Command1_Click()
n = Val(Text1.Text)
a = 0
For i = 2 To n - 1
If (n Mod i) = 0 Then a = 1
If a = 1 Then Exit For
Next i
If a = 0 Then
Text2.Text = Text2.Text & n & "是素数" & vbCrLf
Else
Text2.Text = Text2.Text & n & "不是素数" & vbCrLf
End If
Text1.Text = ""
Text1.SetFocus
End Sub
Private Sub Form_Load()
Me.Caption = "判断是否素数"
Command1.Caption = "判断是否素数"
Command1.Default = True
Text1.Text = ""
Text1.TabIndex = 0
Text2.Text = ""
End Sub
希望你能用得上.
Private Sub Command1_Click()
n = Val(Text1.Text)
a = 0
For i = 2 To n - 1
If (n Mod i) = 0 Then a = 1
If a = 1 Then Exit For
Next i
If a = 0 Then
Text2.Text = Text2.Text & n & "是素数" & vbCrLf
Else
Text2.Text = Text2.Text & n & "不是素数" & vbCrLf
End If
Text1.Text = ""
Text1.SetFocus
End Sub
Private Sub Form_Load()
Me.Caption = "判断是否素数"
Command1.Caption = "判断是否素数"
Command1.Default = True
Text1.Text = ""
Text1.TabIndex = 0
Text2.Text = ""
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
For i = 100 To 999
If IsPrime(i) Then
n = n + 1
Print i;
If n Mod 10 = 0 Then Print
End If
Next i
End Sub
Public Function IsPrime(ByVal num As Long) As Boolean
Dim m As Long
m = Sqr(num)
IsPrime = True
For i = 2 To m
If num Mod i = 0 Then
IsPrime = False
Exit For
End If
Next i
End Function
For i = 100 To 999
If IsPrime(i) Then
n = n + 1
Print i;
If n Mod 10 = 0 Then Print
End If
Next i
End Sub
Public Function IsPrime(ByVal num As Long) As Boolean
Dim m As Long
m = Sqr(num)
IsPrime = True
For i = 2 To m
If num Mod i = 0 Then
IsPrime = False
Exit For
End If
Next i
End Function
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询