随机产生20个10~99的正整数,除去其中的偶数,再将剩余的奇数从大到小排列 用vb编写
问题描述:
随机产生20个10~99的正整数,除去其中的偶数,再将剩余的奇数从大到小排列 用vb编写
答
Dim a%(1 To 20)
For i = 1 To 20
a(i) = Int(Rnd * 90 + 10)
Print a(i);
Next
Print
For i = 1 To 20
If a(i) Mod 2 = 1 Then
Print a(i);
End If
Next
Print
For i = 1 To 19
For j = 20 To i + 1 Step -1
If a(j) > a(j - 1) Then
t = a(j)
a(j) = a(j - 1)
a(j - 1) = t
End If
Next
Next
For i = 1 To 20
If a(i) Mod 2 = 1 Then
Print a(i);
End If
Next