vb程序设计 随机产生一个N位正整数,判断该数是否为素数
展开全部
添加如下控件
Dim shu As Long
Private Sub Command1_Click()
Dim a As Integer, w1 As Integer, w2 As Integer
w1 = 10 ^ Val(Text1)
w2 = 10 ^ (Val(Text1) - 1)
Randomize
shu = Int(Rnd() * (w1 - w2)) + w2
Label3.Caption = "产生的随机数为:" + Str(shu)
End Sub
Private Sub Command2_Click()
Label3.Caption = just_ss(shu)
End Sub
Private Sub Form_Load()
Label1.Caption = "随机生成一个"
Label2.Caption = "位整数"
Label3.Caption = ""
Text1 = ""
Command1.Caption = "产生随机数"
Command2.Caption = "判 断"
End Sub
Function just_ss(a As Long) As String
Dim b As Single, i As Integer
b = a - 1
For i = 2 To b
If a Mod i = 0 Then
just_ss = CStr(a) + " 不是素数"
Exit Function
End If
Next i
just_ss = CStr(a) + " 是素数"
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询