vb编程随即的产生20个0到1000之间的整数
答案:2 悬赏:0 手机版
解决时间 2021-11-26 11:54
- 提问者网友:两耳就是菩提
- 2021-11-25 21:17
vb编程随即的产生20个0到1000之间的整数
最佳答案
- 五星知识达人网友:春色三分
- 2021-11-25 22:27
Private Sub Command1_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
Private Sub Command2_Click()
Dim i As Integer, a() As Integer, s As Integer
Randomize
For i = 1 To 20
ReDim Preserve a(i)
a(i) = Int(1001 * Rnd)
Text1.Text = Text1.Text & a(i) & " "
If a(i) > 500 Then s = s + a(i)
Next i
Text3.Text = s
Call sort(a)
For i = 1 To 20
Text2.Text = Text2.Text & a(i) & " "
Next i
End Sub
Private Sub sort(a() As Integer)
Dim i As Integer, j As Integer, n As Integer, t As Integer
n = UBound(a)
For i = 1 To n - 1
For j = 1 To n - i
If a(j) > a(j + 1) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i
End Sub
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
Private Sub Command2_Click()
Dim i As Integer, a() As Integer, s As Integer
Randomize
For i = 1 To 20
ReDim Preserve a(i)
a(i) = Int(1001 * Rnd)
Text1.Text = Text1.Text & a(i) & " "
If a(i) > 500 Then s = s + a(i)
Next i
Text3.Text = s
Call sort(a)
For i = 1 To 20
Text2.Text = Text2.Text & a(i) & " "
Next i
End Sub
Private Sub sort(a() As Integer)
Dim i As Integer, j As Integer, n As Integer, t As Integer
n = UBound(a)
For i = 1 To n - 1
For j = 1 To n - i
If a(j) > a(j + 1) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i
End Sub
全部回答
- 1楼网友:千夜
- 2021-11-25 22:37
5分?
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯