高校等考试题天天练二级VB]11月2日
分类: 计算机
时间: 2023-04-17 20:20:44
作者: 全国等级考试资料网
知识点:程序问答(二)
程序
Private Sub command1_Click()
Dim a() As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim m As Integer
Dim n As Integer
Randomize Timer
n = 5 + 5 * Rnd()
ReDim a(n)
For i = 1 To n
a(i) = 10 + Rnd() * 89
Print a(i)
Next
Print
For i = 1 To n - 1
k = i
For j = i To n
If a(j) > a(k) Then k = j
Next
If k <> i Then
m = a(i)
a(i) = a(k)
a(k) = m
End If
Next
For i = 1 To n
Print a(i)
Next
End Sub
问题4:请说明以上程序实现的功能。
问题5:在程序运行中将产生几个随机数?
问题6:请说明在程序运行中产生随机数的范围。
程序
Private Sub command1_Click()
Dim a() As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim m As Integer
Dim n As Integer
Randomize Timer
n = 5 + 5 * Rnd()
ReDim a(n)
For i = 1 To n
a(i) = 10 + Rnd() * 89
Print a(i)
Next
For i = 1 To n - 1
k = i
For j = i To n
If a(j) > a(k) Then k = j
Next
If k <> i Then
m = a(i)
a(i) = a(k)
a(k) = m
End If
Next
For i = 1 To n
Print a(i)
Next
End Sub
问题4:请说明以上程序实现的功能。
问题5:在程序运行中将产生几个随机数?
问题6:请说明在程序运行中产生随机数的范围。