用VB,随机生成20个100以内的正整数,将其中的奇数和偶数分两行显示在窗体上? 20
用VB,随机生成20个100以内的正整数,将其中的奇数和偶数分两行显示在窗体上?速度我只要程序代码...
用VB,随机生成20个100以内的正整数,将其中的奇数和偶数分两行显示在窗体上?
速度我只要程序代码 展开
速度我只要程序代码 展开
2个回答
展开全部
Private Sub Form_Activate()
Dim myarray(1 To 20) As Integer
Dim myarray2(1 To 20) As Integer
Dim myarray3(1 To 20) As Integer
Dim j As Integer
j = 1
Dim k As Integer
k = 1
Dim i As Integer
For i = 1 To 20
Randomize
myarray(i) = (1 - 100) * Rnd + 100
If myarray(i) Mod 2 = 0 Then
myarray2(j) = myarray(i)
Else
myarray3(k) = myarray(i)
End If
j = j + 1
k = k + 1
Next i
For j = 1 To 20
If myarray2(j) <> 0 Then
Print myarray2(j);
End If
Next j
Print
For j = 1 To 20
If myarray3(j) <> 0 Then
Print myarray3(j);
End If
Next j
Print
End Sub
Dim myarray(1 To 20) As Integer
Dim myarray2(1 To 20) As Integer
Dim myarray3(1 To 20) As Integer
Dim j As Integer
j = 1
Dim k As Integer
k = 1
Dim i As Integer
For i = 1 To 20
Randomize
myarray(i) = (1 - 100) * Rnd + 100
If myarray(i) Mod 2 = 0 Then
myarray2(j) = myarray(i)
Else
myarray3(k) = myarray(i)
End If
j = j + 1
k = k + 1
Next i
For j = 1 To 20
If myarray2(j) <> 0 Then
Print myarray2(j);
End If
Next j
For j = 1 To 20
If myarray3(j) <> 0 Then
Print myarray3(j);
End If
Next j
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询