vbs定义一个数组, 包含5个元素, 都是随机整数(随便输入), 要求把他们按照从大到小的顺序排列起来
dimnum(4)dimi,n,tfori=0to4num(i)=InputBox("输入随机数")num(i)=int(num(i))nextfori=0to3forn...
dim num(4)
dim i,n,t
for i=0 to 4
num(i)=InputBox("输入随机数")
num(i)=int(num(i))
next
for i=0 to 3
for n=i to 4
if num(i)< num(n) then
t=num(i)
num(i)=num(n)
num(n)=t
End if
next
next
msgbox ("5个随机数为: " & num(0) & "," & num(1) & "," & num(2) & "," & num(3) & "," & num(4))
下面这段没看懂,网上看到是c的冒泡法
求解释一下
for i=0 to 3
for n=i to 4
if num(i)< num(n) then
t=num(i)
num(i)=num(n)
num(n)=t
End if
还有个问题,变量t是什么用的? 展开
dim i,n,t
for i=0 to 4
num(i)=InputBox("输入随机数")
num(i)=int(num(i))
next
for i=0 to 3
for n=i to 4
if num(i)< num(n) then
t=num(i)
num(i)=num(n)
num(n)=t
End if
next
next
msgbox ("5个随机数为: " & num(0) & "," & num(1) & "," & num(2) & "," & num(3) & "," & num(4))
下面这段没看懂,网上看到是c的冒泡法
求解释一下
for i=0 to 3
for n=i to 4
if num(i)< num(n) then
t=num(i)
num(i)=num(n)
num(n)=t
End if
还有个问题,变量t是什么用的? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |