早教吧 育儿知识 作业答案 考试题库 百科 知识分享

Dima(1To5)AsIntegerPrivateSubCommand1Click()Dimi%,k%,t%,x%Fori=1To5a(i)=Int(Rnd*20)Picture1.Printa(i);Space(2);NextiFork=LBound(a())ToUBound(a())Fort=kTo(UBound(a())-1)Ifa(k)>a(t+1)Thenz=a(t+1)a(t+1)=a(k

题目详情
Dim a(1 To 5) As Integer
Private Sub Command1_Click()
Dim i%,k%,t%,x%
For i = 1 To 5
a(i) = Int(Rnd * 20)
Picture1.Print a(i); Space(2);
Next i
For k = LBound(a()) To UBound(a())
For t = k To (UBound(a()) - 1)
If a(k) > a(t + 1) Then
z = a(t + 1)
a(t + 1) = a(k)
a(k) = z
End If
Next t
Next k
For i = 1 To 5
Picture2.Print a(i); Space(2);
Next i
End Sub
▼优质解答
答案和解析
Dim a(1 To 5) As Integer //定义名为a的五元素数组,
Private Sub Command1_Click() //鼠标点击动作
Dim i%, k%, t%, x% //定义四个整形变量
For i = 1 To 5 //for循环
a(i) = Int(Rnd * 20) //给数组a的五个元素赋值,为0-20的随机数
Picture1.Print a(i); Space(2); //在Picture1控件上输出数组a的五个值
Next i //同上
For k = LBound(a()) To UBound(a()) //k从a的下界到上限的for循环
For t = k To (UBound(a()) - 1) //for嵌套t从当前k值到a上限减1
If a(k) > a(t + 1) Then
z = a(t + 1)
a(t + 1) = a(k)
a(k) = z
End If //对数组a的元素进行排序
Next t
Next k
For i = 1 To 5
Picture2.Print a(i); Space(2);//将排序后的结果在控件Picture2中输出
Next i
End Sub//结束
总而言之,就是定义一个数组->赋值->第一次输出->排序->第二次输出 这样一个程序