1樓:匿名使用者
你的程式是完成隨機生成10個兩位整數,然後按由小到大排序,你用的是氣泡排序法。你的程式迴圈裡面的n沒有賦值,即在for j = 1 to n - 1這條語句前,給n加一個賦值語句 n=10。程式如下
private sub command1_click()dim a(1 to 10) as integerdim n as integer, i as integer, j as integer
show
print "原始資料"
randomize
for i = 1 to 10
a(i) = int(rnd * 90) + 10print a(i);
next i
print: print
n=10 '加這條給n賦初值
for j = 1 to n - 1
for i = j + 1 to n
if a(j) > a(i) then
t = a(j): a(j) = a(i): a(i) = tend if
next i
next j
print "排序結果:"
for i = 1 to 10
print a(i);
next i
end sub
2樓:匿名使用者
請把n = 10加到for j = 1 to n - 1的前面,否則n=0迴圈體根本不會執行。
另外,**要注意格式。檢查起來也方便。
option base 1
private sub command1_click()dim a(1 to 10) as integerdim n as integer, i as integer, j as integer
show
print "原始資料"
randomize
for i = 1 to 10
a(i) = int(rnd * 90) + 10print a(i);
next i
print: print
n = 10
for j = 1 to n - 1
for i = j + 1 to n
if a(j) > a(i) then
t = a(j): a(j) = a(i): a(i) = tend if
next i
next j
print "排序結果:"
for i = 1 to 10
print a(i);
next i
end sub
3樓:匿名使用者
你變數n又沒有賦值 n=0 都沒迴圈 當然是。。。
vb排序問題
private sub command1 click dim a 20 as integer for i 1 to 20 randomize a i int rnd 90 10next i for i 1 to 19 for j i 1 to 20 if a i a j then r a i a i...
vb隨機數排序
在窗體中建立三個picture控制元件,並拉伸到適當大小,框中新增如下 執行點選窗體即可。private sub form click dim a 1 to 60 as integer,o 1 to 60 as integer,ji 1 to 60 as integer randomize num1...
VB的簡單氣泡排序
原因有二,一是你沒把變數賦值 因此輸出全是0 二是你的程式有些錯誤,應該是a i 而不是a 1 下面為修改後的程式。private sub command1 click dim a 30 as integer dim i,j,tem as integerconst n 30 給a i 賦值 for ...