作业帮 > 综合 > 作业

产生20个带2位小数的随机数来模拟一组实验数据,设计一个程序对这组数据按从小到大排序.

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/15 15:19:46
产生20个带2位小数的随机数来模拟一组实验数据,设计一个程序对这组数据按从小到大排序.
产生20个带2位小数的随机数来模拟一组实验数据,设计一个程序对这组数据按从小到大排序.
Private Sub Command1_Click()
  Dim a(20) As Double,i As Integer,j As Integer,k As Integer
  Randomize
  Print "原始的数据:"
  For i = 1 To 20
    a(i) = Int(10000 * Rnd()) / 100     '产生100以内的带2位小数的随机数
    Print Format(a(i),"00.00   ");
    If i Mod 10 = 0 Then Print
  Next i
  For i = 1 To 19
    k = i
    For j = i + 1 To 20
      If a(j) < a(k) Then k = j
    Next j
    a(0) = a(i):a(i) = a(k):a(k) = a(0)
  Next i
  Print "排序以后的数据:"
  For i = 1 To 20
    Print Format(a(i),"00.00   ");
    If i Mod 10 = 0 Then Print
  Next i
End Sub