vb随即产生两位正整数30个,显示在文本框1中,求出其中的素数,显示在文本框2中,如图 题三。
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励20(财富值+成长值)
推荐于2017-09-24
展开全部
Dim a(1 To 30) As Integer
Private Sub Command1_Click()
Randomize
For i = 1 To 30 '生成30个两位随机整数,并存放在Text1中
a(i) = Int(Rnd * 90 + 10)
Text1.Text = Text1.Text & Str(a(i)) & Space(2)
Next
End Sub
Private Sub Command2_Click() ' 判素数
For i = 1 To 30
m = 2
n = Int(Sqr(a(i)))
'm在2~根号a(i)范围内,判断a(i)能否整除m,能整除就不是素数,退出循环
Do While m <= n
If a(i) Mod m <> 0 Then
m = m + 1
Else
Exit Do
End If
Loop
If m > n Then ' 是素数
Text2.Text = Text2.Text & Str(a(i)) & Space(2)
End If
Next
End Sub
Private Sub Command1_Click()
Randomize
For i = 1 To 30 '生成30个两位随机整数,并存放在Text1中
a(i) = Int(Rnd * 90 + 10)
Text1.Text = Text1.Text & Str(a(i)) & Space(2)
Next
End Sub
Private Sub Command2_Click() ' 判素数
For i = 1 To 30
m = 2
n = Int(Sqr(a(i)))
'm在2~根号a(i)范围内,判断a(i)能否整除m,能整除就不是素数,退出循环
Do While m <= n
If a(i) Mod m <> 0 Then
m = m + 1
Else
Exit Do
End If
Loop
If m > n Then ' 是素数
Text2.Text = Text2.Text & Str(a(i)) & Space(2)
End If
Next
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
仅供参考。朋友。注意,第一个文本框的multiline多行属性要设置为true
Dim a%(29)
Private Sub Command1_Click()
Text1 = "": Text2 = ""
Randomize
For i = 0 To 29'产生随机数
a(i) = Int(Rnd * 90 + 10)
If i Mod 10 = 0 Then Text1 = Text1 & vbCrLf'输出来文本框1中,每十个数一行
Text1 = Text1 & a(i) & " "
Next
End Sub
Private Sub Command2_Click()
Dim f As Boolean
For i = 0 To 29'求出其中的素数
f = False
For k = 2 To Sqr(a(i))
If a(i) Mod k = 0 Then
f = True
Exit For
End If
Next k
If Not f Then Text2 = Text2 & a(i) & " "'输出到文本框2中
Next i
End Sub
Dim a%(29)
Private Sub Command1_Click()
Text1 = "": Text2 = ""
Randomize
For i = 0 To 29'产生随机数
a(i) = Int(Rnd * 90 + 10)
If i Mod 10 = 0 Then Text1 = Text1 & vbCrLf'输出来文本框1中,每十个数一行
Text1 = Text1 & a(i) & " "
Next
End Sub
Private Sub Command2_Click()
Dim f As Boolean
For i = 0 To 29'求出其中的素数
f = False
For k = 2 To Sqr(a(i))
If a(i) Mod k = 0 Then
f = True
Exit For
End If
Next k
If Not f Then Text2 = Text2 & a(i) & " "'输出到文本框2中
Next i
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询