试题七 VB程序设计题目
挑选单数并排序程序:程序启动后由计算机自动产生20个属于[100,300]之间的随机整数,单击“显示全体”按钮时,在Form1上显示这20个 随机数;单击“显示单数”按钮时,在Form1上显示其中的单数;单击“排序”按钮时,在Form1上将这些单数从小到大显示。要求显示格式为每行显示5个数据。
挑单数并排序
Option Explicit
Dim a(20) As Integer, b(20) As Integer
(1)
Private Sub cmdodd_Click()
Dim I As integer
K=0
For I= 1 To 20
If a(i)/2<>Int(a(i)/2)
Then k=k+1;b(k)=a(i)
(2)
For I=1 To k
Print b(i)
If Int(i/5)=i/5 Then Print
Next I
Print
End Sub
Private Sub cmda11_Click()
Randomize
Dim I As Integer
For I =1 To 20
A(i)=Int(Rnd()*20+100)
Print a(i),
If (3) Then Print
Next I
Print
End Sub
Private Sub cmdsort_Click()
Dim I As Integer
Dim j As Integer
For I=1 To k-1
For j= I to k
If (4) Then temp=b(i):b(i)=b(j):b(j)=temp
Next j
(5)
For I=1 To k
Print b(i)
If Int(i/5)=i/5 Then Print
Next I
End Sub
挑选单数并排序程序:程序启动后由计算机自动产生20个属于[100,300]之间的随机整数,单击“显示全体”按钮时,在Form1上显示这20个 随机数;单击“显示单数”按钮时,在Form1上显示其中的单数;单击“排序”按钮时,在Form1上将这些单数从小到大显示。要求显示格式为每行显示5个数据。
挑单数并排序
Option Explicit
Dim a(20) As Integer, b(20) As Integer
(1)
Private Sub cmdodd_Click()
Dim I As integer
K=0
For I= 1 To 20
If a(i)/2<>Int(a(i)/2)
Then k=k+1;b(k)=a(i)
(2)
For I=1 To k
Print b(i)
If Int(i/5)=i/5 Then Print
Next I
End Sub
Private Sub cmda11_Click()
Randomize
Dim I As Integer
For I =1 To 20
A(i)=Int(Rnd()*20+100)
Print a(i),
If (3) Then Print
Next I
End Sub
Private Sub cmdsort_Click()
Dim I As Integer
Dim j As Integer
For I=1 To k-1
For j= I to k
If (4) Then temp=b(i):b(i)=b(j):b(j)=temp
Next j
(5)
For I=1 To k
Print b(i)
If Int(i/5)=i/5 Then Print
Next I
End Sub