Option Explicit
Private Sub Form_Click()
Dim a(), i, j, j1, n, t
Dim f As Boolean
Randomize
n = CInt(InputBox("请输入多少个随机数", "请输入", "9"))
ReDim a(n)
Print "原数组数:";
For i = 1 To n
a(i) = Int(90 * Rnd) + 10
Print a(i)
Next i
Print
For i = n To 2 Step -1
f = True
For j = 1 To i - 1
If a(j + 1) > a(j) Then t = a(j + 1): a(j + 1) = a(i): a(i) = t
f = False
Next j
If f Then Exit For
Print: Print "第"; n - i + 1; "轮排序后:";
For j1 = 1 To i
Print a(j1);
Next j1
Print
Next i
Print: Print "结果数组";
For i = 1 To n
Print a(i)
Next i
End Sub
VB 求翻译
答案:2 悬赏:70 手机版
解决时间 2021-05-16 08:06
- 提问者网友:藍了天白赴美
- 2021-05-15 17:31
最佳答案
- 五星知识达人网友:大漠
- 2021-05-15 17:49
Option Explicit
Private Sub Form_Click() 窗口被单击
Dim a(), i, j, j1, n, t 定义变量
Dim f As Boolean
Randomize 每次产生不同的随机数
n = CInt(InputBox("请输入多少个随机数", "请输入", "9"))
ReDim a(n) 重新定义数组
Print "原数组数:"; 输出信息
For i = 1 To n 进入循环,从1到n
a(i) = Int(90 * Rnd) + 10 a(i)等于10~90之间的随机数
Print a(i) 输出a(i)
Next i 进入下一个循环
Print 输出一个空行
For i = n To 2 Step -1 进入循环,从n到2,每次减1
f = True 变量f为真
For j = 1 To i - 1 进入循环
If a(j + 1) > a(j) Then t = a(j + 1): a(j + 1) = a(i): a(i) = t 进行从小到大排序
f = False 变量f为假
Next j 下一循环
If f Then Exit For 如果变量f为真,退出循环
Print: Print "第"; n - i + 1; "轮排序后:"; 输出信息
For j1 = 1 To i 循环
Print a(j1); 输出数组a()
Next j1 继续循环,直到输完为止
Print 输出空行
Next i
Print: Print "结果数组"; 输出信息
For i = 1 To n 用循环语句将最后结果输出
Print a(i)
Next i
End Sub
Private Sub Form_Click() 窗口被单击
Dim a(), i, j, j1, n, t 定义变量
Dim f As Boolean
Randomize 每次产生不同的随机数
n = CInt(InputBox("请输入多少个随机数", "请输入", "9"))
ReDim a(n) 重新定义数组
Print "原数组数:"; 输出信息
For i = 1 To n 进入循环,从1到n
a(i) = Int(90 * Rnd) + 10 a(i)等于10~90之间的随机数
Print a(i) 输出a(i)
Next i 进入下一个循环
Print 输出一个空行
For i = n To 2 Step -1 进入循环,从n到2,每次减1
f = True 变量f为真
For j = 1 To i - 1 进入循环
If a(j + 1) > a(j) Then t = a(j + 1): a(j + 1) = a(i): a(i) = t 进行从小到大排序
f = False 变量f为假
Next j 下一循环
If f Then Exit For 如果变量f为真,退出循环
Print: Print "第"; n - i + 1; "轮排序后:"; 输出信息
For j1 = 1 To i 循环
Print a(j1); 输出数组a()
Next j1 继续循环,直到输完为止
Print 输出空行
Next i
Print: Print "结果数组"; 输出信息
For i = 1 To n 用循环语句将最后结果输出
Print a(i)
Next i
End Sub
全部回答
- 1楼网友:轮獄道
- 2021-05-15 19:20
就是 由用户定义产生几个数 再将这几个数排列 将排好的数 从小到大的循序 输出
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯